From f443bd3bafa65dfc07718443acc2416f02a087e8 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Thu, 5 Dec 2019 19:07:45 -0800 Subject: [PATCH] Ditch decimal_formatter (#1363) --- include/fmt/format.h | 54 -------------------------------------------- 1 file changed, 54 deletions(-) diff --git a/include/fmt/format.h b/include/fmt/format.h index 770cc145..46ada8d6 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -802,60 +802,6 @@ template <> int count_digits<4>(internal::fallback_uintptr n); # define FMT_ALWAYS_INLINE #endif -// Computes g = floor(log10(n)) and calls h.on(n); -template FMT_ALWAYS_INLINE char* lg(uint32_t n, Handler h) { - return n < 100 ? n < 10 ? h.template on<0>(n) : h.template on<1>(n) - : n < 1000000 - ? n < 10000 ? n < 1000 ? h.template on<2>(n) - : h.template on<3>(n) - : n < 100000 ? h.template on<4>(n) - : h.template on<5>(n) - : n < 100000000 ? n < 10000000 ? h.template on<6>(n) - : h.template on<7>(n) - : n < 1000000000 ? h.template on<8>(n) - : h.template on<9>(n); -} - -// An lg handler that formats a decimal number. -// Usage: lg(n, decimal_formatter(buffer)); -class decimal_formatter { - private: - char* buffer_; - - void write_pair(unsigned N, uint32_t index) { - std::memcpy(buffer_ + N, data::digits + index * 2, 2); - } - - public: - explicit decimal_formatter(char* buf) : buffer_(buf) {} - - template char* on(uint32_t u) { - if (N == 0) { - *buffer_ = static_cast(u) + '0'; - } else if (N == 1) { - write_pair(0, u); - } else { - // The idea of using 4.32 fixed-point numbers is based on - // https://github.com/jeaiii/itoa - unsigned n = N - 1; - unsigned a = n / 5 * n * 53 / 16; - uint64_t t = - ((1ULL << (32 + a)) / data::zero_or_powers_of_10_32[n] + 1 - n / 9); - t = ((t * u) >> a) + n / 5 * 4; - write_pair(0, t >> 32); - for (unsigned i = 2; i < N; i += 2) { - t = 100ULL * static_cast(t); - write_pair(i, t >> 32); - } - if (N % 2 == 0) { - buffer_[N] = - static_cast((10ULL * static_cast(t)) >> 32) + '0'; - } - } - return buffer_ += N + 1; - } -}; - #ifdef FMT_BUILTIN_CLZ // Optional version of count_digits for better performance on 32-bit platforms. inline int count_digits(uint32_t n) {