https://gcc.gnu.org/bugzilla/show_bug.cgi?id=50160
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Last reconfirmed| |2026-05-05
Status|UNCONFIRMED |NEW
Ever confirmed|0 |1
--- Comment #45 from Jonathan Wakely <redi at gcc dot gnu.org> ---
We can just do something like this:
--- a/libstdc++-v3/include/bits/stl_vector.h
+++ b/libstdc++-v3/include/bits/stl_vector.h
@@ -2351,8 +2351,27 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
constexpr __detail::__synth3way_t<_Tp>
operator<=>(const vector<_Tp, _Alloc>& __x, const vector<_Tp, _Alloc>&
__y)
{
- return std::lexicographical_compare_three_way(__x.begin(), __x.end(),
- __y.begin(), __y.end(),
+ auto __x_begin = __x.begin(), __x_end = __x.end();
+ auto __y_begin = __y.begin(), __y_end = __y.end();
+
+#ifdef FIX
+ if constexpr (is_same_v<_Tp, bool>)
+ {
+ auto __x_first = __x_begin._M_p, __x_last = __x_end._M_p;
+ auto __y_first = __y_begin._M_p, __y_last = __y_end._M_p;
+ while (__x_first != __x_last && __y_first != __y_last
+ && *__x_first == *__y_first)
+ {
+ ++__x_first;
+ ++__y_first;
+ }
+ __x_begin = _Bit_iterator(__x_first, 0);
+ __y_begin = _Bit_iterator(__y_first, 0);
+ }
+#endif
+
+ return std::lexicographical_compare_three_way(__x_begin, __x_end,
+ __y_begin, __y_end,
__detail::__synth3way);
}
#else
This way we only do bitwise iteration for the words that are not equal. We
could still optimize the comparison for the non-equal words, but this already
makes a big difference.