diff options
author | Jonathan Wakely <jwakely@redhat.com> | 2024-02-08 15:46:08 +0000 |
---|---|---|
committer | Jonathan Wakely <redi@gcc.gnu.org> | 2024-08-01 21:56:56 +0100 |
commit | e1729eb80489e6c8e03d7c9a072736350407c7f4 (patch) | |
tree | c1e40bdf1901d021193fdff34dde2da39896b497 | |
parent | 0ba18853f7dbb038449322fea2ae311c2b26ceb6 (diff) | |
download | gcc-e1729eb80489e6c8e03d7c9a072736350407c7f4.zip gcc-e1729eb80489e6c8e03d7c9a072736350407c7f4.tar.gz gcc-e1729eb80489e6c8e03d7c9a072736350407c7f4.tar.bz2 |
libstdc++: Use memcmp to optimize std::bitset::_M_is_equal() [PR113807]
As noted in the PR the compiler doesn't seem able to do this on its own,
so we get better code at all optimization levels by using memcmp.
libstdc++-v3/ChangeLog:
PR libstdc++/113807
* include/std/bitset (bitset::_M_is_equal()): Use memcmp to
optimize operator==.
-rw-r--r-- | libstdc++-v3/include/std/bitset | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/libstdc++-v3/include/std/bitset b/libstdc++-v3/include/std/bitset index ccd6d19..e5d677f 100644 --- a/libstdc++-v3/include/std/bitset +++ b/libstdc++-v3/include/std/bitset @@ -205,10 +205,16 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER _GLIBCXX14_CONSTEXPR bool _M_is_equal(const _Base_bitset<_Nw>& __x) const _GLIBCXX_NOEXCEPT { - for (size_t __i = 0; __i < _Nw; ++__i) - if (_M_w[__i] != __x._M_w[__i]) - return false; - return true; +#if __cplusplus >= 201402L + if (__builtin_is_constant_evaluated()) + { + for (size_t __i = 0; __i < _Nw; ++__i) + if (_M_w[__i] != __x._M_w[__i]) + return false; + return true; + } +#endif + return !__builtin_memcmp(_M_w, __x._M_w, _Nw * sizeof(_WordT)); } template<size_t _Nb> |