[v2,2/4] libstdc++: Optimize std::add_pointer compilation performance

Message ID 20240214135252.1416047-2-kmatsui@gcc.gnu.org
State Unresolved
Headers
Series [v2,1/4] c++: Implement __add_pointer built-in trait |

Checks

Context Check Description
snail/gcc-patch-check warning Git am fail log

Commit Message

Ken Matsui Feb. 14, 2024, 1:52 p.m. UTC
  This patch optimizes the compilation performance of std::add_pointer
by dispatching to the new __add_pointer built-in trait.

libstdc++-v3/ChangeLog:

	* include/std/type_traits (add_pointer): Use __add_pointer
	built-in trait.

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

Comments

Patrick Palka Feb. 14, 2024, 8:20 p.m. UTC | #1
On Wed, 14 Feb 2024, Ken Matsui wrote:

> This patch optimizes the compilation performance of std::add_pointer
> by dispatching to the new __add_pointer built-in trait.
> 
> libstdc++-v3/ChangeLog:
> 
> 	* include/std/type_traits (add_pointer): Use __add_pointer
> 	built-in trait.

LGTM

> 
> Signed-off-by: Ken Matsui <kmatsui@gcc.gnu.org>
> ---
>  libstdc++-v3/include/std/type_traits | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits
> index 21402fd8c13..3bde7cb8ba3 100644
> --- a/libstdc++-v3/include/std/type_traits
> +++ b/libstdc++-v3/include/std/type_traits
> @@ -2121,6 +2121,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
>      { };
>  #endif
>  
> +  /// add_pointer
> +#if _GLIBCXX_USE_BUILTIN_TRAIT(__add_pointer)
> +  template<typename _Tp>
> +    struct add_pointer
> +    { using type = __add_pointer(_Tp); };
> +#else
>    template<typename _Tp, typename = void>
>      struct __add_pointer_helper
>      { using type = _Tp; };
> @@ -2129,7 +2135,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
>      struct __add_pointer_helper<_Tp, __void_t<_Tp*>>
>      { using type = _Tp*; };
>  
> -  /// add_pointer
>    template<typename _Tp>
>      struct add_pointer
>      : public __add_pointer_helper<_Tp>
> @@ -2142,6 +2147,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
>    template<typename _Tp>
>      struct add_pointer<_Tp&&>
>      { using type = _Tp*; };
> +#endif
>  
>  #if __cplusplus > 201103L
>    /// Alias template for remove_pointer
> -- 
> 2.43.0
> 
>
  

Patch

diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits
index 21402fd8c13..3bde7cb8ba3 100644
--- a/libstdc++-v3/include/std/type_traits
+++ b/libstdc++-v3/include/std/type_traits
@@ -2121,6 +2121,12 @@  _GLIBCXX_BEGIN_NAMESPACE_VERSION
     { };
 #endif
 
+  /// add_pointer
+#if _GLIBCXX_USE_BUILTIN_TRAIT(__add_pointer)
+  template<typename _Tp>
+    struct add_pointer
+    { using type = __add_pointer(_Tp); };
+#else
   template<typename _Tp, typename = void>
     struct __add_pointer_helper
     { using type = _Tp; };
@@ -2129,7 +2135,6 @@  _GLIBCXX_BEGIN_NAMESPACE_VERSION
     struct __add_pointer_helper<_Tp, __void_t<_Tp*>>
     { using type = _Tp*; };
 
-  /// add_pointer
   template<typename _Tp>
     struct add_pointer
     : public __add_pointer_helper<_Tp>
@@ -2142,6 +2147,7 @@  _GLIBCXX_BEGIN_NAMESPACE_VERSION
   template<typename _Tp>
     struct add_pointer<_Tp&&>
     { using type = _Tp*; };
+#endif
 
 #if __cplusplus > 201103L
   /// Alias template for remove_pointer