| 1048 | } |
| 1049 | |
| 1050 | template <typename T> FMT_CONSTEXPR auto count_digits_fallback(T n) -> int { |
| 1051 | int count = 1; |
| 1052 | for (;;) { |
| 1053 | // Integer division is slow so do it for a group of four digits instead |
| 1054 | // of for every digit. The idea comes from the talk by Alexandrescu |
| 1055 | // "Three Optimization Tips for C++". See speed-test for a comparison. |
| 1056 | if (n < 10) return count; |
| 1057 | if (n < 100) return count + 1; |
| 1058 | if (n < 1000) return count + 2; |
| 1059 | if (n < 10000) return count + 3; |
| 1060 | n /= 10000u; |
| 1061 | count += 4; |
| 1062 | } |
| 1063 | } |
| 1064 | #if FMT_USE_INT128 |
| 1065 | FMT_CONSTEXPR inline auto count_digits(native_uint128 n) -> int { |
| 1066 | return count_digits_fallback(n); |