| 550 | // Formats a decimal unsigned integer value writing into buffer. |
| 551 | template <typename UInt, typename Char> |
| 552 | inline void format_decimal(Char *buffer, UInt value, unsigned num_digits) { |
| 553 | --num_digits; |
| 554 | while (value >= 100) { |
| 555 | // Integer division is slow so do it for a group of two digits instead |
| 556 | // of for every digit. The idea comes from the talk by Alexandrescu |
| 557 | // "Three Optimization Tips for C++". See speed-test for a comparison. |
| 558 | unsigned index = (value % 100) * 2; |
| 559 | value /= 100; |
| 560 | buffer[num_digits] = DIGITS[index + 1]; |
| 561 | buffer[num_digits - 1] = DIGITS[index]; |
| 562 | num_digits -= 2; |
| 563 | } |
| 564 | if (value < 10) { |
| 565 | *buffer = static_cast<char>('0' + value); |
| 566 | return; |
| 567 | } |
| 568 | unsigned index = static_cast<unsigned>(value * 2); |
| 569 | buffer[1] = DIGITS[index + 1]; |
| 570 | buffer[0] = DIGITS[index]; |
| 571 | } |
| 572 | |
| 573 | #ifdef _WIN32 |
| 574 | // A converter from UTF-8 to UTF-16. |
no outgoing calls
no test coverage detected