mirror of
https://github.com/fmtlib/fmt.git
synced 2025-08-01 03:34:45 +02:00
Use digit pairs as in unrolledlut
This commit is contained in:
@@ -239,12 +239,27 @@ template <> FMT_FUNC int count_digits<4>(detail::fallback_uintptr n) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
const char basic_data<T>::digits[] =
|
const typename basic_data<T>::digit_pair basic_data<T>::digits[] = {
|
||||||
"0001020304050607080910111213141516171819"
|
{'0', '0'}, {'0', '1'}, {'0', '2'}, {'0', '3'}, {'0', '4'},
|
||||||
"2021222324252627282930313233343536373839"
|
{'0', '5'}, {'0', '6'}, {'0', '7'}, {'0', '8'}, {'0', '9'},
|
||||||
"4041424344454647484950515253545556575859"
|
{'1', '0'}, {'1', '1'}, {'1', '2'}, {'1', '3'}, {'1', '4'},
|
||||||
"6061626364656667686970717273747576777879"
|
{'1', '5'}, {'1', '6'}, {'1', '7'}, {'1', '8'}, {'1', '9'},
|
||||||
"8081828384858687888990919293949596979899";
|
{'2', '0'}, {'2', '1'}, {'2', '2'}, {'2', '3'}, {'2', '4'},
|
||||||
|
{'2', '5'}, {'2', '6'}, {'2', '7'}, {'2', '8'}, {'2', '9'},
|
||||||
|
{'3', '0'}, {'3', '1'}, {'3', '2'}, {'3', '3'}, {'3', '4'},
|
||||||
|
{'3', '5'}, {'3', '6'}, {'3', '7'}, {'3', '8'}, {'3', '9'},
|
||||||
|
{'4', '0'}, {'4', '1'}, {'4', '2'}, {'4', '3'}, {'4', '4'},
|
||||||
|
{'4', '5'}, {'4', '6'}, {'4', '7'}, {'4', '8'}, {'4', '9'},
|
||||||
|
{'5', '0'}, {'5', '1'}, {'5', '2'}, {'5', '3'}, {'5', '4'},
|
||||||
|
{'5', '5'}, {'5', '6'}, {'5', '7'}, {'5', '8'}, {'5', '9'},
|
||||||
|
{'6', '0'}, {'6', '1'}, {'6', '2'}, {'6', '3'}, {'6', '4'},
|
||||||
|
{'6', '5'}, {'6', '6'}, {'6', '7'}, {'6', '8'}, {'6', '9'},
|
||||||
|
{'7', '0'}, {'7', '1'}, {'7', '2'}, {'7', '3'}, {'7', '4'},
|
||||||
|
{'7', '5'}, {'7', '6'}, {'7', '7'}, {'7', '8'}, {'7', '9'},
|
||||||
|
{'8', '0'}, {'8', '1'}, {'8', '2'}, {'8', '3'}, {'8', '4'},
|
||||||
|
{'8', '5'}, {'8', '6'}, {'8', '7'}, {'8', '8'}, {'8', '9'},
|
||||||
|
{'9', '0'}, {'9', '1'}, {'9', '2'}, {'9', '3'}, {'9', '4'},
|
||||||
|
{'9', '5'}, {'9', '6'}, {'9', '7'}, {'9', '8'}, {'9', '9'}};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
const char basic_data<T>::hex_digits[] = "0123456789abcdef";
|
const char basic_data<T>::hex_digits[] = "0123456789abcdef";
|
||||||
|
@@ -752,7 +752,9 @@ template <typename T = void> struct FMT_EXTERN_TEMPLATE_API basic_data {
|
|||||||
static const uint64_t zero_or_powers_of_10_64[];
|
static const uint64_t zero_or_powers_of_10_64[];
|
||||||
static const uint64_t pow10_significands[];
|
static const uint64_t pow10_significands[];
|
||||||
static const int16_t pow10_exponents[];
|
static const int16_t pow10_exponents[];
|
||||||
static const char digits[];
|
// GCC generates slightly better code for pairs than chars.
|
||||||
|
using digit_pair = char[2];
|
||||||
|
static const digit_pair digits[];
|
||||||
static const char hex_digits[];
|
static const char hex_digits[];
|
||||||
static const char foreground_color[];
|
static const char foreground_color[];
|
||||||
static const char background_color[];
|
static const char background_color[];
|
||||||
@@ -903,7 +905,7 @@ inline format_decimal_result<Char*> format_decimal(Char* out, UInt value,
|
|||||||
// of for every digit. The idea comes from the talk by Alexandrescu
|
// of for every digit. The idea comes from the talk by Alexandrescu
|
||||||
// "Three Optimization Tips for C++". See speed-test for a comparison.
|
// "Three Optimization Tips for C++". See speed-test for a comparison.
|
||||||
out -= 2;
|
out -= 2;
|
||||||
copy2(out, data::digits + static_cast<unsigned>((value % 100) * 2));
|
copy2(out, data::digits[value % 100]);
|
||||||
value /= 100;
|
value /= 100;
|
||||||
}
|
}
|
||||||
if (value < 10) {
|
if (value < 10) {
|
||||||
@@ -911,7 +913,7 @@ inline format_decimal_result<Char*> format_decimal(Char* out, UInt value,
|
|||||||
return {out, end};
|
return {out, end};
|
||||||
}
|
}
|
||||||
out -= 2;
|
out -= 2;
|
||||||
copy2(out, data::digits + static_cast<unsigned>(value * 2));
|
copy2(out, data::digits[value]);
|
||||||
return {out, end};
|
return {out, end};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1085,12 +1087,12 @@ template <typename Char, typename It> It write_exponent(int exp, It it) {
|
|||||||
*it++ = static_cast<Char>('+');
|
*it++ = static_cast<Char>('+');
|
||||||
}
|
}
|
||||||
if (exp >= 100) {
|
if (exp >= 100) {
|
||||||
const char* top = data::digits + (exp / 100) * 2;
|
const char* top = data::digits[exp / 100];
|
||||||
if (exp >= 1000) *it++ = static_cast<Char>(top[0]);
|
if (exp >= 1000) *it++ = static_cast<Char>(top[0]);
|
||||||
*it++ = static_cast<Char>(top[1]);
|
*it++ = static_cast<Char>(top[1]);
|
||||||
exp %= 100;
|
exp %= 100;
|
||||||
}
|
}
|
||||||
const char* d = data::digits + exp * 2;
|
const char* d = data::digits[exp];
|
||||||
*it++ = static_cast<Char>(d[0]);
|
*it++ = static_cast<Char>(d[0]);
|
||||||
*it++ = static_cast<Char>(d[1]);
|
*it++ = static_cast<Char>(d[1]);
|
||||||
return it;
|
return it;
|
||||||
|
Reference in New Issue
Block a user