Tested aarch64-linux and x86_64-linux. Pushed to trunk.

-- >8 --

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.
---
 libstdc++-v3/include/std/bitset | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/libstdc++-v3/include/std/bitset b/libstdc++-v3/include/std/bitset
index 3243c649731..16c4040f532 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
-- 
2.43.0

Reply via email to