Skip to content

Commit

Permalink
Move data to functions
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaut committed Apr 28, 2021
1 parent ab7c33e commit 84a36b9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
4 changes: 0 additions & 4 deletions include/fmt/format-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,6 @@ template <> FMT_FUNC int count_digits<4>(detail::fallback_uintptr n) {

#if __cplusplus < 201703L
template <typename T>
constexpr const uint32_t basic_data<T>::zero_or_powers_of_10_32[];
template <typename T>
constexpr const uint64_t basic_data<T>::zero_or_powers_of_10_64[];
template <typename T>
constexpr const typename basic_data<T>::digit_pair basic_data<T>::digits[];
template <typename T> constexpr const char basic_data<T>::hex_digits[];
template <typename T> constexpr const char basic_data<T>::signs[];
Expand Down
16 changes: 7 additions & 9 deletions include/fmt/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -911,13 +911,6 @@ using uint64_or_128_t = conditional_t<num_bits<T>() <= 64, uint64_t, uint128_t>;

// Static data is placed in this class template for the header-only config.
template <typename T = void> 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;

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 84a36b9

Please sign in to comment.