Message ID | 20240110194031.2384005-7-kmatsui@gcc.gnu.org |
---|---|
State | New |
Headers | show |
Series | Optimize integral-related type traits | expand |
On Wed, 10 Jan 2024 at 19:47, Ken Matsui <kmatsui@gcc.gnu.org> wrote: > > This patch optimizes the compilation performance of std::is_arithmetic > by dispatching to the new __is_arithmetic built-in trait. OK for trunk (if the new built-in is approved). > > libstdc++-v3/ChangeLog: > > * include/std/type_traits (is_arithmetic): Use __is_arithmetic > built-in trait. > (is_arithmetic_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 23ea70eca18..9baf3b2aa46 100644 > --- a/libstdc++-v3/include/std/type_traits > +++ b/libstdc++-v3/include/std/type_traits > @@ -728,10 +728,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION > #endif > > /// is_arithmetic > +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_arithmetic) > + template<typename _Tp> > + struct is_arithmetic > + : public __bool_constant<__is_arithmetic(_Tp)> > + { }; > +#else > template<typename _Tp> > struct is_arithmetic > : public __or_<is_integral<_Tp>, is_floating_point<_Tp>>::type > { }; > +#endif > > /// is_fundamental > template<typename _Tp> > @@ -3317,8 +3324,14 @@ template <typename _Tp> > inline constexpr bool is_reference_v<_Tp&&> = true; > #endif > > +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_arithmetic) > +template <typename _Tp> > + inline constexpr bool is_arithmetic_v = __is_arithmetic(_Tp); > +#else > template <typename _Tp> > inline constexpr bool is_arithmetic_v = is_arithmetic<_Tp>::value; > +#endif > + > template <typename _Tp> > inline constexpr bool is_fundamental_v = is_fundamental<_Tp>::value; > > -- > 2.43.0 >
diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 23ea70eca18..9baf3b2aa46 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -728,10 +728,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #endif /// is_arithmetic +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_arithmetic) + template<typename _Tp> + struct is_arithmetic + : public __bool_constant<__is_arithmetic(_Tp)> + { }; +#else template<typename _Tp> struct is_arithmetic : public __or_<is_integral<_Tp>, is_floating_point<_Tp>>::type { }; +#endif /// is_fundamental template<typename _Tp> @@ -3317,8 +3324,14 @@ template <typename _Tp> inline constexpr bool is_reference_v<_Tp&&> = true; #endif +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_arithmetic) +template <typename _Tp> + inline constexpr bool is_arithmetic_v = __is_arithmetic(_Tp); +#else template <typename _Tp> inline constexpr bool is_arithmetic_v = is_arithmetic<_Tp>::value; +#endif + template <typename _Tp> inline constexpr bool is_fundamental_v = is_fundamental<_Tp>::value;
This patch optimizes the compilation performance of std::is_arithmetic by dispatching to the new __is_arithmetic built-in trait. libstdc++-v3/ChangeLog: * include/std/type_traits (is_arithmetic): Use __is_arithmetic built-in trait. (is_arithmetic_v): Likewise. Signed-off-by: Ken Matsui <kmatsui@gcc.gnu.org> --- libstdc++-v3/include/std/type_traits | 13 +++++++++++++ 1 file changed, 13 insertions(+)