Skip to content

Commit 84a36b9

Browse files
committed
Move data to functions
1 parent ab7c33e commit 84a36b9

File tree

2 files changed

+7
-13
lines changed

2 files changed

+7
-13
lines changed

include/fmt/format-inl.h

-4
Original file line numberDiff line numberDiff line change
@@ -225,10 +225,6 @@ template <> FMT_FUNC int count_digits<4>(detail::fallback_uintptr n) {
225225

226226
#if __cplusplus < 201703L
227227
template <typename T>
228-
constexpr const uint32_t basic_data<T>::zero_or_powers_of_10_32[];
229-
template <typename T>
230-
constexpr const uint64_t basic_data<T>::zero_or_powers_of_10_64[];
231-
template <typename T>
232228
constexpr const typename basic_data<T>::digit_pair basic_data<T>::digits[];
233229
template <typename T> constexpr const char basic_data<T>::hex_digits[];
234230
template <typename T> constexpr const char basic_data<T>::signs[];

include/fmt/format.h

+7-9
Original file line numberDiff line numberDiff line change
@@ -911,13 +911,6 @@ using uint64_or_128_t = conditional_t<num_bits<T>() <= 64, uint64_t, uint128_t>;
911911

912912
// Static data is placed in this class template for the header-only config.
913913
template <typename T = void> struct basic_data {
914-
static constexpr const uint32_t zero_or_powers_of_10_32[] = {
915-
0, 0, FMT_POWERS_OF_10(1U)};
916-
917-
static constexpr const uint64_t zero_or_powers_of_10_64[] = {
918-
0, 0, FMT_POWERS_OF_10(1U), FMT_POWERS_OF_10(1000000000ULL),
919-
10000000000000000000ULL};
920-
921914
// log10(2) = 0x0.4d104d427de7fbcc...
922915
static const uint64_t log10_2_significand = 0x4d104d427de7fbcc;
923916

@@ -993,7 +986,10 @@ FMT_CONSTEXPR20 inline int count_digits(uint64_t n) {
993986
#ifdef FMT_BUILTIN_CLZLL
994987
// https://github.com/fmtlib/format-benchmark/blob/master/digits10
995988
auto t = bsr2log10(FMT_BUILTIN_CLZLL(n | 1) ^ 63);
996-
return t - (n < data::zero_or_powers_of_10_64[t]);
989+
constexpr const uint64_t zero_or_powers_of_10[] = {
990+
0, 0, FMT_POWERS_OF_10(1U), FMT_POWERS_OF_10(1000000000ULL),
991+
10000000000000000000ULL};
992+
return t - (n < zero_or_powers_of_10[t]);
997993
#else
998994
return count_digits_fallback(n);
999995
#endif
@@ -1029,7 +1025,9 @@ FMT_CONSTEXPR20 inline int count_digits(uint32_t n) {
10291025
return count_digits_fallback(n);
10301026
}
10311027
auto t = bsr2log10(FMT_BUILTIN_CLZ(n | 1) ^ 31);
1032-
return t - (n < data::zero_or_powers_of_10_32[t]);
1028+
constexpr const uint32_t zero_or_powers_of_10[] = {0, 0,
1029+
FMT_POWERS_OF_10(1U)};
1030+
return t - (n < zero_or_powers_of_10[t]);
10331031
}
10341032
#endif
10351033

0 commit comments

Comments
 (0)