]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Compare keys and values separately in flat_map::operator==
authorPatrick Palka <ppalka@redhat.com>
Thu, 29 May 2025 14:12:23 +0000 (10:12 -0400)
committerPatrick Palka <ppalka@redhat.com>
Thu, 29 May 2025 14:12:23 +0000 (10:12 -0400)
Instead of effectively doing a zipped comparison of the keys and values,
compare them separately to leverage the underlying containers' optimized
equality implementations.

libstdc++-v3/ChangeLog:

* include/std/flat_map (_Flat_map_impl::operator==): Compare
keys and values separately.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
libstdc++-v3/include/std/flat_map

index cec7f36cff9fe5f46d8eb101a20667c1a59e2970..4bd4963c2ad7cf0fb8b54374a965302d150a13d7 100644 (file)
@@ -873,7 +873,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       [[nodiscard]]
       friend bool
       operator==(const _Derived& __x, const _Derived& __y)
-      { return std::equal(__x.begin(), __x.end(), __y.begin(), __y.end()); }
+      {
+       return __x._M_cont.keys == __y._M_cont.keys
+         && __x._M_cont.values == __y._M_cont.values;
+      }
 
       template<typename _Up = value_type>
        [[nodiscard]]