From 045c23906075127704b62b00ba3b711273b69be2 Mon Sep 17 00:00:00 2001 From: Giulio Eulisse <10544+ktf@users.noreply.github.com> Date: Sat, 29 Jun 2024 15:15:15 +0200 Subject: [PATCH] DPL Analysis: speedup prune_voids_pack --- Framework/Foundation/include/Framework/Pack.h | 41 ++++++++++++++++--- .../test/test_FunctionalHelpers.cxx | 3 ++ 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/Framework/Foundation/include/Framework/Pack.h b/Framework/Foundation/include/Framework/Pack.h index e0593a6175b3a..89555ee45f20c 100644 --- a/Framework/Foundation/include/Framework/Pack.h +++ b/Framework/Foundation/include/Framework/Pack.h @@ -115,14 +115,45 @@ consteval auto prune_voids_pack(Result result, pack<>) return result; } +// The first one is non void, but one of the others is void template + requires(!std::is_void_v) consteval auto prune_voids_pack(pack result, pack) { - if constexpr (std::is_void_v == false) { - return prune_voids_pack(pack{}, pack{}); - } else { - return prune_voids_pack(pack{}, pack{}); - } + return prune_voids_pack(pack{}, pack{}); +} + +// The first one is void +template + requires(std::is_void_v) +consteval auto prune_voids_pack(pack result, pack) +{ + return prune_voids_pack(pack{}, pack{}); +} + +// The first one is non void, but one of the others is void +template + requires(!std::is_void_v && !std::is_void_v) +consteval auto prune_voids_pack(pack result, pack) +{ + return prune_voids_pack(pack{}, pack{}); +} + +// Eats 4 types at the time +template + requires(!std::is_void_v && !std::is_void_v && !std::is_void_v && !std::is_void_v) +consteval auto prune_voids_pack(pack result, pack) +{ + return prune_voids_pack(pack{}, pack{}); +} + +// Eats 8 types at the time +template + requires(!std::is_void_v && !std::is_void_v && !std::is_void_v && !std::is_void_v && !std::is_void_v && !std::is_void_v && !std::is_void_v && !std::is_void_v) +consteval auto prune_voids_pack(pack result, pack) +{ + return prune_voids_pack(pack{}, pack{}); } /// Selects from the pack types that satisfy the Condition diff --git a/Framework/Foundation/test/test_FunctionalHelpers.cxx b/Framework/Foundation/test/test_FunctionalHelpers.cxx index 334da9ac1d5f5..895133ae6428d 100644 --- a/Framework/Foundation/test/test_FunctionalHelpers.cxx +++ b/Framework/Foundation/test/test_FunctionalHelpers.cxx @@ -32,6 +32,7 @@ TEST_CASE("TestOverride") static_assert(has_type(pack{}) == false, "double should not be in the pack"); static_assert(has_type_v> == true, "int should be in the pack"); static_assert(has_type_v> == false, "double should not be in the pack"); + static_assert(std::is_same_v{})), pack>, "prune last void"); static_assert(has_type_conditional_v> == true, "int should be in the pack"); static_assert(has_type_conditional_v> == false, "double should not be in the pack"); @@ -42,6 +43,8 @@ TEST_CASE("TestOverride") static_assert(has_type_at_conditional(pack()) == 3 + 1, "bool is not in the pack so the function returns size + 1"); static_assert(std::is_same_v, pack>, "selector should select int"); + static_assert(std::is_same_v, pack>, "selector should select int"); + static_assert(std::is_same_v, pack>, "selector should select int"); static_assert(std::is_same_v, pack>, pack>, "multiselector should select int"); static_assert(std::is_same_v, pack>, "filter should remove int"); static_assert(std::is_same_v, pack>, pack>, "filter intersect two packs");