[14/14] libstdc++: Optimize std::is_scalar compilation performance

Message ID 20240110194031.2384005-15-kmatsui@gcc.gnu.org
State Unresolved
Headers
Series Optimize integral-related type traits |

Checks

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

Commit Message

Ken Matsui Jan. 10, 2024, 9:23 a.m. UTC
  This patch optimizes the compilation performance of std::is_scalar
by dispatching to the new __is_scalar built-in trait.

libstdc++-v3/ChangeLog:

	* include/std/type_traits (is_scalar): Use __is_scalar built-in
	trait.
	(is_scalar_v): Likewise.

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

Comments

Jonathan Wakely Jan. 10, 2024, 9:22 p.m. UTC | #1
On Wed, 10 Jan 2024 at 19:47, Ken Matsui <kmatsui@gcc.gnu.org> wrote:
>
> This patch optimizes the compilation performance of std::is_scalar
> by dispatching to the new __is_scalar built-in trait.

OK for trunk (if the new built-in is approved).


>
> libstdc++-v3/ChangeLog:
>
>         * include/std/type_traits (is_scalar): Use __is_scalar built-in
>         trait.
>         (is_scalar_v): Likewise.
>
> Signed-off-by: Ken Matsui <kmatsui@gcc.gnu.org>
> ---
>  libstdc++-v3/include/std/type_traits | 13 +++++++++++++
>  1 file changed, 13 insertions(+)
>
> diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits
> index b917c743aea..9ace6a9f08f 100644
> --- a/libstdc++-v3/include/std/type_traits
> +++ b/libstdc++-v3/include/std/type_traits
> @@ -775,11 +775,18 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
>      struct is_member_pointer;
>
>    /// is_scalar
> +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_scalar)
> +  template<typename _Tp>
> +    struct is_scalar
> +    : public __bool_constant<__is_scalar(_Tp)>
> +    { };
> +#else
>    template<typename _Tp>
>      struct is_scalar
>      : public __or_<is_arithmetic<_Tp>, is_enum<_Tp>, is_pointer<_Tp>,
>                     is_member_pointer<_Tp>, is_null_pointer<_Tp>>::type
>      { };
> +#endif
>
>    /// is_compound
>    template<typename _Tp>
> @@ -3369,8 +3376,14 @@ template <typename _Tp>
>    inline constexpr bool is_object_v = is_object<_Tp>::value;
>  #endif
>
> +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_scalar)
> +template <typename _Tp>
> +  inline constexpr bool is_scalar_v = __is_scalar(_Tp);
> +#else
>  template <typename _Tp>
>    inline constexpr bool is_scalar_v = is_scalar<_Tp>::value;
> +#endif
> +
>  template <typename _Tp>
>    inline constexpr bool is_compound_v = !is_fundamental_v<_Tp>;
>
> --
> 2.43.0
>
  

Patch

diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits
index b917c743aea..9ace6a9f08f 100644
--- a/libstdc++-v3/include/std/type_traits
+++ b/libstdc++-v3/include/std/type_traits
@@ -775,11 +775,18 @@  _GLIBCXX_BEGIN_NAMESPACE_VERSION
     struct is_member_pointer;
 
   /// is_scalar
+#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_scalar)
+  template<typename _Tp>
+    struct is_scalar
+    : public __bool_constant<__is_scalar(_Tp)>
+    { };
+#else
   template<typename _Tp>
     struct is_scalar
     : public __or_<is_arithmetic<_Tp>, is_enum<_Tp>, is_pointer<_Tp>,
                    is_member_pointer<_Tp>, is_null_pointer<_Tp>>::type
     { };
+#endif
 
   /// is_compound
   template<typename _Tp>
@@ -3369,8 +3376,14 @@  template <typename _Tp>
   inline constexpr bool is_object_v = is_object<_Tp>::value;
 #endif
 
+#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_scalar)
+template <typename _Tp>
+  inline constexpr bool is_scalar_v = __is_scalar(_Tp);
+#else
 template <typename _Tp>
   inline constexpr bool is_scalar_v = is_scalar<_Tp>::value;
+#endif
+
 template <typename _Tp>
   inline constexpr bool is_compound_v = !is_fundamental_v<_Tp>;