diff options
author | Jonathan Wakely <jwakely@redhat.com> | 2024-02-08 15:46:08 +0000 |
---|---|---|
committer | Jonathan Wakely <jwakely@redhat.com> | 2024-02-15 11:43:21 +0000 |
commit | e7ae13a858f36031b8fd3aa07362752ff2b19b2e (patch) | |
tree | fc4f13fcdc7078977efe5dae0b25a9a5db6a52c6 /libstdc++-v3 | |
parent | 4d819db7f229a23cb15ef68f310e0bb51d201c45 (diff) | |
download | gcc-e7ae13a858f36031b8fd3aa07362752ff2b19b2e.zip gcc-e7ae13a858f36031b8fd3aa07362752ff2b19b2e.tar.gz gcc-e7ae13a858f36031b8fd3aa07362752ff2b19b2e.tar.bz2 |
libstdc++: Use memset to optimize std::bitset::set() [PR113807]
As pointed out in the PR we already do this for reset().
libstdc++-v3/ChangeLog:
PR libstdc++/113807
* include/std/bitset (bitset::set()): Use memset instead of a
loop over the individual words.
Diffstat (limited to 'libstdc++-v3')
-rw-r--r-- | libstdc++-v3/include/std/bitset | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/libstdc++-v3/include/std/bitset b/libstdc++-v3/include/std/bitset index 3243c64..16c4040 100644 --- a/libstdc++-v3/include/std/bitset +++ b/libstdc++-v3/include/std/bitset @@ -177,8 +177,15 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER _GLIBCXX14_CONSTEXPR void _M_do_set() _GLIBCXX_NOEXCEPT { - for (size_t __i = 0; __i < _Nw; __i++) - _M_w[__i] = ~static_cast<_WordT>(0); +#if __cplusplus >= 201402L + if (__builtin_is_constant_evaluated()) + { + for (_WordT& __w : _M_w) + __w = ~static_cast<_WordT>(0);; + return; + } +#endif + __builtin_memset(_M_w, 0xFF, _Nw * sizeof(_WordT)); } _GLIBCXX14_CONSTEXPR void |