diff --git a/format.h b/format.h index d384cfef..6b6951ac 100644 --- a/format.h +++ b/format.h @@ -712,24 +712,23 @@ inline unsigned count_digits(uint32_t n) { // Formats a decimal unsigned integer value writing into buffer. template inline void format_decimal(Char *buffer, UInt value, unsigned num_digits) { - --num_digits; + buffer += num_digits; while (value >= 100) { // Integer division is slow so do it for a group of two digits instead // of for every digit. The idea comes from the talk by Alexandrescu // "Three Optimization Tips for C++". See speed-test for a comparison. unsigned index = (value % 100) * 2; value /= 100; - buffer[num_digits] = Data::DIGITS[index + 1]; - buffer[num_digits - 1] = Data::DIGITS[index]; - num_digits -= 2; + *--buffer = Data::DIGITS[index + 1]; + *--buffer = Data::DIGITS[index]; } if (value < 10) { - *buffer = static_cast('0' + value); + *--buffer = static_cast('0' + value); return; } unsigned index = static_cast(value * 2); - buffer[1] = Data::DIGITS[index + 1]; - buffer[0] = Data::DIGITS[index]; + *--buffer = Data::DIGITS[index + 1]; + *--buffer = Data::DIGITS[index]; } #ifndef _WIN32