public inbox for libstdc++-cvs@sourceware.org help / color / mirror / Atom feed
From: Jonathan Wakely <redi@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r13-2814] libstdc++: Optimize std::bitset<N>::to_string Date: Fri, 23 Sep 2022 11:58:18 +0000 (GMT) [thread overview] Message-ID: <20220923115818.97C423858C52@sourceware.org> (raw) https://gcc.gnu.org/g:ffb03fa12850df3a4f53435d5f20ff122c83732a commit r13-2814-gffb03fa12850df3a4f53435d5f20ff122c83732a Author: Jonathan Wakely <jwakely@redhat.com> Date: Thu Sep 22 18:36:04 2022 +0100 libstdc++: Optimize std::bitset<N>::to_string This makes to_string approximately twice as fast at any optimization level. Instead of iterating through every bit, jump straight to the next bit that is set, by using _Find_first and _Find_next. libstdc++-v3/ChangeLog: * include/std/bitset (bitset::_M_copy_to_string): Find set bits instead of iterating over individual bits. Diff: --- libstdc++-v3/include/std/bitset | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/libstdc++-v3/include/std/bitset b/libstdc++-v3/include/std/bitset index 0c84f15fda0..83c6416b770 100644 --- a/libstdc++-v3/include/std/bitset +++ b/libstdc++-v3/include/std/bitset @@ -1495,9 +1495,12 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER _CharT __zero, _CharT __one) const { __s.assign(_Nb, __zero); - for (size_t __i = _Nb; __i > 0; --__i) - if (_Unchecked_test(__i - 1)) - _Traits::assign(__s[_Nb - __i], __one); + size_t __n = this->_Find_first(); + while (__n < _Nb) + { + __s[_Nb - __n - 1] = __one; + __n = _Find_next(__n); + } } #endif // HOSTED
reply other threads:[~2022-09-23 11:58 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20220923115818.97C423858C52@sourceware.org \ --to=redi@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ --cc=libstdc++-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).