Skip to content

Commit

Permalink
libstdc++: Optimize is_array trait performance
Browse files Browse the repository at this point in the history
This patch optimizes the performance of the is_array trait by dispatching to
the new __is_array built-in trait.

libstdc++-v3/ChangeLog:

	* include/std/type_traits (is_array): Use __is_array built-in trait.
	(is_array_v): Likewise.

Signed-off-by: Ken Matsui <kmatsui@gcc.gnu.org>
  • Loading branch information
ken-matsui authored and ouuleilei-bot committed Sep 17, 2023
1 parent 145e5a7 commit c3f697d
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions libstdc++-v3/include/std/type_traits
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{ };

/// is_array
#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_array)
template<typename _Tp>
struct is_array
: public __bool_constant<__is_array(_Tp)>
{ };
#else
template<typename>
struct is_array
: public false_type { };
Expand All @@ -514,6 +520,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
template<typename _Tp>
struct is_array<_Tp[]>
: public true_type { };
#endif

template<typename>
struct __is_pointer_helper
Expand Down Expand Up @@ -3175,12 +3182,17 @@ template <typename _Tp>
template <typename _Tp>
inline constexpr bool is_floating_point_v = is_floating_point<_Tp>::value;

#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_array)
template <typename _Tp>
inline constexpr bool is_array_v = __is_array(_Tp);
#else
template <typename _Tp>
inline constexpr bool is_array_v = false;
template <typename _Tp>
inline constexpr bool is_array_v<_Tp[]> = true;
template <typename _Tp, size_t _Num>
inline constexpr bool is_array_v<_Tp[_Num]> = true;
#endif

template <typename _Tp>
inline constexpr bool is_pointer_v = is_pointer<_Tp>::value;
Expand Down

0 comments on commit c3f697d

Please sign in to comment.