From: Ken Matsui Date: Thu, 15 Feb 2024 15:19:02 +0000 (-0800) Subject: libstdc++: Optimize std::rank compilation performance X-Git-Tag: basepoints/gcc-16~8301 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=6f0dfa6f1acdf78d764d6f5d6f53c2f2a768c047;p=thirdparty%2Fgcc.git libstdc++: Optimize std::rank compilation performance This patch optimizes the compilation performance of std::rank by dispatching to the new __array_rank built-in trait. libstdc++-v3/ChangeLog: * include/std/type_traits (rank): Use __array_rank built-in trait. (rank_v): Likewise. Signed-off-by: Ken Matsui Reviewed-by: Patrick Palka Reviewed-by: Jonathan Wakely --- diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 3d158f993a8..5402574efe9 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -1447,6 +1447,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION }; /// rank +#if _GLIBCXX_USE_BUILTIN_TRAIT(__array_rank) + template + struct rank + : public integral_constant { }; +#else template struct rank : public integral_constant { }; @@ -1458,6 +1463,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template struct rank<_Tp[]> : public integral_constant::value> { }; +#endif /// extent template @@ -3531,12 +3537,17 @@ template template inline constexpr size_t alignment_of_v = alignment_of<_Tp>::value; +#if _GLIBCXX_USE_BUILTIN_TRAIT(__array_rank) +template + inline constexpr size_t rank_v = __array_rank(_Tp); +#else template inline constexpr size_t rank_v = 0; template inline constexpr size_t rank_v<_Tp[_Size]> = 1 + rank_v<_Tp>; template inline constexpr size_t rank_v<_Tp[]> = 1 + rank_v<_Tp>; +#endif template inline constexpr size_t extent_v = 0;