From 84a36b99bfe0898daf194b666575fcfd5e23673c Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Tue, 27 Apr 2021 17:06:29 -0700 Subject: [PATCH] Move data to functions --- include/fmt/format-inl.h | 4 ---- include/fmt/format.h | 16 +++++++--------- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/include/fmt/format-inl.h b/include/fmt/format-inl.h index c9c4a14d..0527bb58 100644 --- a/include/fmt/format-inl.h +++ b/include/fmt/format-inl.h @@ -225,10 +225,6 @@ template <> FMT_FUNC int count_digits<4>(detail::fallback_uintptr n) { #if __cplusplus < 201703L template -constexpr const uint32_t basic_data::zero_or_powers_of_10_32[]; -template -constexpr const uint64_t basic_data::zero_or_powers_of_10_64[]; -template constexpr const typename basic_data::digit_pair basic_data::digits[]; template constexpr const char basic_data::hex_digits[]; template constexpr const char basic_data::signs[]; diff --git a/include/fmt/format.h b/include/fmt/format.h index 4bc4229c..c4329ec9 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -911,13 +911,6 @@ using uint64_or_128_t = conditional_t() <= 64, uint64_t, uint128_t>; // Static data is placed in this class template for the header-only config. template struct basic_data { - static constexpr const uint32_t zero_or_powers_of_10_32[] = { - 0, 0, FMT_POWERS_OF_10(1U)}; - - static constexpr const uint64_t zero_or_powers_of_10_64[] = { - 0, 0, FMT_POWERS_OF_10(1U), FMT_POWERS_OF_10(1000000000ULL), - 10000000000000000000ULL}; - // log10(2) = 0x0.4d104d427de7fbcc... static const uint64_t log10_2_significand = 0x4d104d427de7fbcc; @@ -993,7 +986,10 @@ FMT_CONSTEXPR20 inline int count_digits(uint64_t n) { #ifdef FMT_BUILTIN_CLZLL // https://github.com/fmtlib/format-benchmark/blob/master/digits10 auto t = bsr2log10(FMT_BUILTIN_CLZLL(n | 1) ^ 63); - return t - (n < data::zero_or_powers_of_10_64[t]); + constexpr const uint64_t zero_or_powers_of_10[] = { + 0, 0, FMT_POWERS_OF_10(1U), FMT_POWERS_OF_10(1000000000ULL), + 10000000000000000000ULL}; + return t - (n < zero_or_powers_of_10[t]); #else return count_digits_fallback(n); #endif @@ -1029,7 +1025,9 @@ FMT_CONSTEXPR20 inline int count_digits(uint32_t n) { return count_digits_fallback(n); } auto t = bsr2log10(FMT_BUILTIN_CLZ(n | 1) ^ 31); - return t - (n < data::zero_or_powers_of_10_32[t]); + constexpr const uint32_t zero_or_powers_of_10[] = {0, 0, + FMT_POWERS_OF_10(1U)}; + return t - (n < zero_or_powers_of_10[t]); } #endif