Skip to content

Commit 7b10347

Browse files
committed
DPL: speedup homogeneous_apply_ref for less than 20 elements
Adding the requires statement should reduce greatly work done by the compiler to build and then optimise out the if constexprs.
1 parent 34eb6f4 commit 7b10347

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

Framework/Foundation/include/Framework/StructToTuple.h

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,13 +163,19 @@ consteval auto brace_constructible_size(auto... Members)
163163
return std::array<decltype(l(p0)), d##0>{DPL_FENUM_##d##0(l, p, )}; \
164164
}
165165

166-
template <bool B = false, typename L, class T>
167-
auto homogeneous_apply_refs(L l, T&& object)
166+
template <bool B, typename T>
167+
consteval int nested_brace_constructible_size()
168168
{
169169
using type = std::decay_t<T>;
170170
constexpr int nesting = B ? 1 : 0;
171-
constexpr unsigned long numElements = brace_constructible_size<type>() - nesting;
172-
static_assert(numElements < 99, "Too many elements in the struct");
171+
return brace_constructible_size<type>() - nesting;
172+
}
173+
174+
template <bool B = false, typename L, class T>
175+
requires(nested_brace_constructible_size<B, T>() < 99 && nested_brace_constructible_size<B, T>() >= 20)
176+
auto homogeneous_apply_refs(L l, T&& object)
177+
{
178+
constexpr unsigned long numElements = nested_brace_constructible_size<B, T>();
173179
// clang-format off
174180
if DPL_HOMOGENEOUS_APPLY_ENTRY (9, 9)
175181
else if DPL_HOMOGENEOUS_APPLY_ENTRY (9, 8)
@@ -251,7 +257,17 @@ auto homogeneous_apply_refs(L l, T&& object)
251257
else if DPL_HOMOGENEOUS_APPLY_ENTRY (2, 2)
252258
else if DPL_HOMOGENEOUS_APPLY_ENTRY (2, 1)
253259
else if DPL_HOMOGENEOUS_APPLY_ENTRY_TENS (2)
254-
else if DPL_HOMOGENEOUS_APPLY_ENTRY (1, 9)
260+
else { return std::array<bool,0>(); }
261+
// clang-format on
262+
}
263+
264+
template <bool B = false, typename L, class T>
265+
requires(nested_brace_constructible_size<B, T>() < 20 && nested_brace_constructible_size<B, T>() >= 0)
266+
auto homogeneous_apply_refs(L l, T&& object)
267+
{
268+
constexpr unsigned long numElements = nested_brace_constructible_size<B, T>();
269+
// clang-format off
270+
if DPL_HOMOGENEOUS_APPLY_ENTRY (1, 9)
255271
else if DPL_HOMOGENEOUS_APPLY_ENTRY (1, 8)
256272
else if DPL_HOMOGENEOUS_APPLY_ENTRY (1, 7)
257273
else if DPL_HOMOGENEOUS_APPLY_ENTRY (1, 6)

0 commit comments

Comments
 (0)