| 14340 | std::is_same<NumberType, number_integer_t>::value, |
| 14341 | int> = 0> |
| 14342 | void dump_integer(NumberType x) |
| 14343 | { |
| 14344 | static constexpr std::array<std::array<char, 2>, 100> digits_to_99 |
| 14345 | { |
| 14346 | { |
| 14347 | {{'0', '0'}}, {{'0', '1'}}, {{'0', '2'}}, {{'0', '3'}}, {{'0', '4'}}, {{'0', '5'}}, {{'0', '6'}}, {{'0', '7'}}, {{'0', '8'}}, {{'0', '9'}}, |
| 14348 | {{'1', '0'}}, {{'1', '1'}}, {{'1', '2'}}, {{'1', '3'}}, {{'1', '4'}}, {{'1', '5'}}, {{'1', '6'}}, {{'1', '7'}}, {{'1', '8'}}, {{'1', '9'}}, |
| 14349 | {{'2', '0'}}, {{'2', '1'}}, {{'2', '2'}}, {{'2', '3'}}, {{'2', '4'}}, {{'2', '5'}}, {{'2', '6'}}, {{'2', '7'}}, {{'2', '8'}}, {{'2', '9'}}, |
| 14350 | {{'3', '0'}}, {{'3', '1'}}, {{'3', '2'}}, {{'3', '3'}}, {{'3', '4'}}, {{'3', '5'}}, {{'3', '6'}}, {{'3', '7'}}, {{'3', '8'}}, {{'3', '9'}}, |
| 14351 | {{'4', '0'}}, {{'4', '1'}}, {{'4', '2'}}, {{'4', '3'}}, {{'4', '4'}}, {{'4', '5'}}, {{'4', '6'}}, {{'4', '7'}}, {{'4', '8'}}, {{'4', '9'}}, |
| 14352 | {{'5', '0'}}, {{'5', '1'}}, {{'5', '2'}}, {{'5', '3'}}, {{'5', '4'}}, {{'5', '5'}}, {{'5', '6'}}, {{'5', '7'}}, {{'5', '8'}}, {{'5', '9'}}, |
| 14353 | {{'6', '0'}}, {{'6', '1'}}, {{'6', '2'}}, {{'6', '3'}}, {{'6', '4'}}, {{'6', '5'}}, {{'6', '6'}}, {{'6', '7'}}, {{'6', '8'}}, {{'6', '9'}}, |
| 14354 | {{'7', '0'}}, {{'7', '1'}}, {{'7', '2'}}, {{'7', '3'}}, {{'7', '4'}}, {{'7', '5'}}, {{'7', '6'}}, {{'7', '7'}}, {{'7', '8'}}, {{'7', '9'}}, |
| 14355 | {{'8', '0'}}, {{'8', '1'}}, {{'8', '2'}}, {{'8', '3'}}, {{'8', '4'}}, {{'8', '5'}}, {{'8', '6'}}, {{'8', '7'}}, {{'8', '8'}}, {{'8', '9'}}, |
| 14356 | {{'9', '0'}}, {{'9', '1'}}, {{'9', '2'}}, {{'9', '3'}}, {{'9', '4'}}, {{'9', '5'}}, {{'9', '6'}}, {{'9', '7'}}, {{'9', '8'}}, {{'9', '9'}}, |
| 14357 | } |
| 14358 | }; |
| 14359 | |
| 14360 | // special case for "0" |
| 14361 | if (x == 0) |
| 14362 | { |
| 14363 | o->write_character('0'); |
| 14364 | return; |
| 14365 | } |
| 14366 | |
| 14367 | // use a pointer to fill the buffer |
| 14368 | auto buffer_ptr = number_buffer.begin(); |
| 14369 | |
| 14370 | const bool is_negative = std::is_same<NumberType, number_integer_t>::value and not(x >= 0); // see issue #755 |
| 14371 | number_unsigned_t abs_value; |
| 14372 | |
| 14373 | unsigned int n_chars; |
| 14374 | |
| 14375 | if (is_negative) |
| 14376 | { |
| 14377 | *buffer_ptr = '-'; |
| 14378 | abs_value = remove_sign(x); |
| 14379 | |
| 14380 | // account one more byte for the minus sign |
| 14381 | n_chars = 1 + count_digits(abs_value); |
| 14382 | } |
| 14383 | else |
| 14384 | { |
| 14385 | abs_value = static_cast<number_unsigned_t>(x); |
| 14386 | n_chars = count_digits(abs_value); |
| 14387 | } |
| 14388 | |
| 14389 | // spare 1 byte for '\0' |
| 14390 | assert(n_chars < number_buffer.size() - 1); |
| 14391 | |
| 14392 | // jump to the end to generate the string from backward |
| 14393 | // so we later avoid reversing the result |
| 14394 | buffer_ptr += n_chars; |
| 14395 | |
| 14396 | // Fast int2ascii implementation inspired by "Fastware" talk by Andrei Alexandrescu |
| 14397 | // See: https://www.youtube.com/watch?v=o4-CwDo2zpg |
| 14398 | while (abs_value >= 100) |
| 14399 | { |
nothing calls this directly
no test coverage detected