]> gcc.gnu.org Git - gcc.git/commitdiff
libstdc++: Stop using std::__is_pointer in <deque> and <algorithm> [PR115497]
authorJonathan Wakely <jwakely@redhat.com>
Wed, 19 Jun 2024 16:21:16 +0000 (17:21 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Fri, 21 Jun 2024 16:07:00 +0000 (17:07 +0100)
This replaces all uses of the std::__is_pointer type trait with uses of
the new __is_pointer built-in. Since the class template was only used to
enable some performance optimizations for algorithms, we can use the
built-in when __has_builtin(__is_pointer) is true (which is the case for
GCC trunk and for current versions of Clang) and just forego the
optimization otherwise.

Removing the uses of std::__is_pointer means it can be removed from
<bits/cpp_type_traits.h>, which is another step towards fixing PR
115497.

libstdc++-v3/ChangeLog:

PR libstdc++/115497
* include/bits/deque.tcc (__lex_cmp_dit): Replace __is_pointer
class template with __is_pointer(T) built-in.
(__lexicographical_compare_aux1): Likewise.
* include/bits/stl_algobase.h (__equal_aux1): Likewise.
(__lexicographical_compare_aux1): Likewise.

libstdc++-v3/include/bits/deque.tcc
libstdc++-v3/include/bits/stl_algobase.h

index 2c12358ca5bf4362f5c8dabfbe13b26a0b1e3258..deb010a0ebb5e0335d5f1e5da552cff582aa2c59 100644 (file)
@@ -1271,18 +1271,21 @@ _GLIBCXX_END_NAMESPACE_CONTAINER
        _GLIBCXX_STD_C::_Deque_iterator<_Tp1, _Ref, _Ptr> __last1,
        const _Tp2* __first2, const _Tp2* __last2)
     {
+#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_pointer)
       const bool __simple =
        (__is_memcmp_ordered_with<_Tp1, _Tp2>::__value
-        && __is_pointer<_Ptr>::__value
+        && __is_pointer(_Ptr)
 #if __cplusplus > 201703L && __cpp_lib_concepts
         // For C++20 iterator_traits<volatile T*>::value_type is non-volatile
         // so __is_byte<T> could be true, but we can't use memcmp with
         // volatile data.
-        && !is_volatile_v<_Tp1>
-        && !is_volatile_v<_Tp2>
+        && !is_volatile_v<_Tp1> && !is_volatile_v<_Tp2>
 #endif
         );
       typedef std::__lexicographical_compare<__simple> _Lc;
+#else
+      typedef std::__lexicographical_compare<false> _Lc;
+#endif
 
       while (__first1._M_node != __last1._M_node)
        {
@@ -1327,19 +1330,21 @@ _GLIBCXX_END_NAMESPACE_CONTAINER
                _GLIBCXX_STD_C::_Deque_iterator<_Tp2, _Ref2, _Ptr2> __first2,
                _GLIBCXX_STD_C::_Deque_iterator<_Tp2, _Ref2, _Ptr2> __last2)
     {
+#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_pointer)
       const bool __simple =
        (__is_memcmp_ordered_with<_Tp1, _Tp2>::__value
-        && __is_pointer<_Ptr1>::__value
-        && __is_pointer<_Ptr2>::__value
+        && __is_pointer(_Ptr1) && __is_pointer(_Ptr2)
 #if __cplusplus > 201703L && __cpp_lib_concepts
         // For C++20 iterator_traits<volatile T*>::value_type is non-volatile
         // so __is_byte<T> could be true, but we can't use memcmp with
         // volatile data.
-        && !is_volatile_v<_Tp1>
-        && !is_volatile_v<_Tp2>
+        && !is_volatile_v<_Tp1> && !is_volatile_v<_Tp2>
 #endif
         );
       typedef std::__lexicographical_compare<__simple> _Lc;
+#else
+      typedef std::__lexicographical_compare<false> _Lc;
+#endif
 
       while (__first1 != __last1)
        {
index 1a0f8c14073e983fba6b5b813712c75ead61ec4f..57ff2f7cb082ef6b1ffd402a1f892155555dbe19 100644 (file)
@@ -1256,8 +1256,10 @@ _GLIBCXX_END_NAMESPACE_CONTAINER
     {
       typedef typename iterator_traits<_II1>::value_type _ValueType1;
       const bool __simple = ((__is_integer<_ValueType1>::__value
-                             || __is_pointer<_ValueType1>::__value)
-                            && __memcmpable<_II1, _II2>::__value);
+#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_pointer)
+                             || __is_pointer(_ValueType1)
+#endif
+                            ) && __memcmpable<_II1, _II2>::__value);
       return std::__equal<__simple>::equal(__first1, __last1, __first2);
     }
 
@@ -1420,10 +1422,10 @@ _GLIBCXX_END_NAMESPACE_CONTAINER
     {
       typedef typename iterator_traits<_II1>::value_type _ValueType1;
       typedef typename iterator_traits<_II2>::value_type _ValueType2;
+#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_pointer)
       const bool __simple =
        (__is_memcmp_ordered_with<_ValueType1, _ValueType2>::__value
-        && __is_pointer<_II1>::__value
-        && __is_pointer<_II2>::__value
+        && __is_pointer(_II1) && __is_pointer(_II2)
 #if __cplusplus > 201703L && __glibcxx_concepts
         // For C++20 iterator_traits<volatile T*>::value_type is non-volatile
         // so __is_byte<T> could be true, but we can't use memcmp with
@@ -1432,6 +1434,9 @@ _GLIBCXX_END_NAMESPACE_CONTAINER
         && !is_volatile_v<remove_reference_t<iter_reference_t<_II2>>>
 #endif
         );
+#else
+      const bool __simple = false;
+#endif
 
       return std::__lexicographical_compare<__simple>::__lc(__first1, __last1,
                                                            __first2, __last2);
This page took 0.094974 seconds and 5 git commands to generate.