From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7934) id 83748386EC2D; Sat, 16 Dec 2023 17:00:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 83748386EC2D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1702746045; bh=dhid+Aeav8JxvKpIE9OBBJPL8VvrXy9HQxl/Y/eqaGk=; h=From:To:Subject:Date:From; b=fOX64O+0EFLqqOIo/t1Q+ZbB5f4r9WJzw3YehBGB6MVHx1Tjmn1HbkZ/XFSLvxXYu 21CFdKkEntZ+00xpLEgRzAu4xiwTJw9kfOaoJX4kfH7rgZQw4DGY7+QW7InzGA86aC BdA5tQIh77xssNsBzgloLb16CeSXPLpXHi/4gFog= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Ken Matsui To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r14-6630] libstdc++: Optimize std::is_function compilation performance X-Act-Checkin: gcc X-Git-Author: Ken Matsui X-Git-Refname: refs/heads/master X-Git-Oldrev: e86cfcaef246331ee7956dd86c156d594768fe70 X-Git-Newrev: cdd4387c5b6aeace2e58318691a5880d29157db9 Message-Id: <20231216170045.83748386EC2D@sourceware.org> Date: Sat, 16 Dec 2023 17:00:45 +0000 (GMT) List-Id: https://gcc.gnu.org/g:cdd4387c5b6aeace2e58318691a5880d29157db9 commit r14-6630-gcdd4387c5b6aeace2e58318691a5880d29157db9 Author: Ken Matsui Date: Sat Jun 10 21:01:39 2023 -0700 libstdc++: Optimize std::is_function compilation performance This patch optimizes the compilation performance of std::is_function by dispatching to the new __is_function built-in trait. libstdc++-v3/ChangeLog: * include/std/type_traits (is_function): Use __is_function built-in trait. (is_function_v): Likewise. Optimize its implementation. Move this under is_const_v as this depends on is_const_v. Signed-off-by: Ken Matsui Reviewed-by: Jonathan Wakely Diff: --- libstdc++-v3/include/std/type_traits | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index db880d87f60..b6d0441129b 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -637,6 +637,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { }; /// is_function +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_function) + template + struct is_function + : public __bool_constant<__is_function(_Tp)> + { }; +#else template struct is_function : public __bool_constant::value> { }; @@ -648,6 +654,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template struct is_function<_Tp&&> : public false_type { }; +#endif #ifdef __cpp_lib_is_null_pointer // C++ >= 11 /// is_null_pointer (LWG 2247). @@ -3255,8 +3262,7 @@ template inline constexpr bool is_union_v = __is_union(_Tp); template inline constexpr bool is_class_v = __is_class(_Tp); -template - inline constexpr bool is_function_v = is_function<_Tp>::value; +// is_function_v is defined below, after is_const_v. #if _GLIBCXX_USE_BUILTIN_TRAIT(__is_reference) template @@ -3293,6 +3299,19 @@ template inline constexpr bool is_const_v = false; template inline constexpr bool is_const_v = true; + +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_function) +template + inline constexpr bool is_function_v = __is_function(_Tp); +#else +template + inline constexpr bool is_function_v = !is_const_v; +template + inline constexpr bool is_function_v<_Tp&> = false; +template + inline constexpr bool is_function_v<_Tp&&> = false; +#endif + template inline constexpr bool is_volatile_v = false; template