Skip to content

Commit

Permalink
Optimise size calculation for fundamental types in compute_encoded_si…
Browse files Browse the repository at this point in the history
…ze_and_cache_string_lengths
  • Loading branch information
odygrd committed Sep 22, 2024
1 parent f09c351 commit 7719a47
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions include/quill/core/Codec.h
Original file line number Diff line number Diff line change
Expand Up @@ -269,24 +269,19 @@ QUILL_NODISCARD QUILL_ATTRIBUTE_HOT size_t compute_encoded_size_and_cache_string
QUILL_MAYBE_UNUSED detail::SizeCacheVector& conditional_arg_size_cache,
QUILL_MAYBE_UNUSED Args const&... args) noexcept
{
if constexpr (std::conjunction_v<std::disjunction<std::is_arithmetic<detail::remove_cvref_t<Args>>, std::is_enum<detail::remove_cvref_t<Args>>,
std::is_same<detail::remove_cvref_t<Args>, void const*>>...>)
if constexpr (!std::conjunction_v<std::disjunction<std::is_arithmetic<detail::remove_cvref_t<Args>>, std::is_enum<detail::remove_cvref_t<Args>>,
std::is_same<detail::remove_cvref_t<Args>, void const*>>...>)
{
// If all arguments are fundamental types, calculate the total size directly.
return (0ull + ... + sizeof(Args));
}
else
{
// Always clear the cache since we're processing non-fundamental types
// Always clear the cache when we're processing non-fundamental types
conditional_arg_size_cache.clear();

size_t total_sum{0};
// Avoid using a fold expression with '+ ...' because we require a guaranteed evaluation
// order to ensure that each argument is processed in sequence. This is essential for
// correctly populating the conditional_arg_size_cache
((total_sum += Codec<detail::remove_cvref_t<Args>>::compute_encoded_size(conditional_arg_size_cache, args)), ...);
return total_sum;
}

size_t total_sum{0};
// Avoid using a fold expression with '+ ...' because we require a guaranteed evaluation
// order to ensure that each argument is processed in sequence. This is essential for
// correctly populating the conditional_arg_size_cache
((total_sum += Codec<detail::remove_cvref_t<Args>>::compute_encoded_size(conditional_arg_size_cache, args)), ...);
return total_sum;
}

/**
Expand Down

0 comments on commit 7719a47

Please sign in to comment.