From 1a10e904b59a42f05e9e7b64863129a78aca3cb2 Mon Sep 17 00:00:00 2001 From: Daniel Bertalan Date: Tue, 27 Jun 2023 07:48:39 +0200 Subject: [PATCH] AK: Use compiler builtins for `MakeIntegerSequence`/`TypeListElement` These recursive templates have a measurable impact on the compile speed of Variant-heavy code like LibWeb. Using these builtins leads to a 2.5% speedup for the measured compilation units. --- AK/StdLibExtraDetails.h | 8 ++++++++ AK/TypeList.h | 7 +++++++ 2 files changed, 15 insertions(+) diff --git a/AK/StdLibExtraDetails.h b/AK/StdLibExtraDetails.h index e7c3d7405d..54cc7849a8 100644 --- a/AK/StdLibExtraDetails.h +++ b/AK/StdLibExtraDetails.h @@ -454,6 +454,13 @@ struct IntegerSequence { template using IndexSequence = IntegerSequence; +#if __has_builtin(__make_integer_seq) +template +using MakeIntegerSequence = __make_integer_seq; +#elif __has_builtin(__integer_pack) +template +using MakeIntegerSequence = IntegerSequence; +#else template auto make_integer_sequence_impl() { @@ -465,6 +472,7 @@ auto make_integer_sequence_impl() template using MakeIntegerSequence = decltype(make_integer_sequence_impl()); +#endif template using MakeIndexSequence = MakeIntegerSequence; diff --git a/AK/TypeList.h b/AK/TypeList.h index 2c28da3445..e2f3d13e8f 100644 --- a/AK/TypeList.h +++ b/AK/TypeList.h @@ -16,6 +16,12 @@ struct TypeList; template struct TypeListElement; +#if __has_builtin(__type_pack_element) +template +struct TypeListElement> { + using Type = __type_pack_element; +}; +#else template struct TypeListElement> : TypeListElement> { @@ -25,6 +31,7 @@ template struct TypeListElement<0, TypeList> { using Type = Head; }; +#endif template struct TypeList {