[v14,19/40] libstdc++: Optimize is_member_function_pointer trait performance

Message ID 20230915235353.19378-20-kmatsui@gcc.gnu.org
State Superseded
Headers
Series Optimize type traits performance |

Commit Message

Ken Matsui Sept. 15, 2023, 11:51 p.m. UTC
  This patch optimizes the performance of the is_member_function_pointer trait
by dispatching to the new __is_member_function_pointer built-in trait.

libstdc++-v3/ChangeLog:

	* include/std/type_traits (is_member_function_pointer): Use
	__is_member_function_pointer built-in trait.
	(is_member_function_pointer_v): Likewise.

Signed-off-by: Ken Matsui <kmatsui@gcc.gnu.org>
---
 libstdc++-v3/include/std/type_traits | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
  

Patch

diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits
index d7f89cf7c06..e1b10240dc2 100644
--- a/libstdc++-v3/include/std/type_traits
+++ b/libstdc++-v3/include/std/type_traits
@@ -588,6 +588,13 @@  _GLIBCXX_BEGIN_NAMESPACE_VERSION
     : public __is_member_object_pointer_helper<__remove_cv_t<_Tp>>::type
     { };
 
+#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_member_function_pointer)
+  /// is_member_function_pointer
+  template<typename _Tp>
+    struct is_member_function_pointer
+    : public __bool_constant<__is_member_function_pointer(_Tp)>
+    { };
+#else
   template<typename>
     struct __is_member_function_pointer_helper
     : public false_type { };
@@ -601,6 +608,7 @@  _GLIBCXX_BEGIN_NAMESPACE_VERSION
     struct is_member_function_pointer
     : public __is_member_function_pointer_helper<__remove_cv_t<_Tp>>::type
     { };
+#endif
 
   /// is_enum
   template<typename _Tp>
@@ -3222,9 +3230,17 @@  template <typename _Tp>
 template <typename _Tp>
   inline constexpr bool is_member_object_pointer_v =
     is_member_object_pointer<_Tp>::value;
+
+#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_member_function_pointer)
+template <typename _Tp>
+  inline constexpr bool is_member_function_pointer_v =
+    __is_member_function_pointer(_Tp);
+#else
 template <typename _Tp>
   inline constexpr bool is_member_function_pointer_v =
     is_member_function_pointer<_Tp>::value;
+#endif
+
 template <typename _Tp>
   inline constexpr bool is_enum_v = __is_enum(_Tp);
 template <typename _Tp>