1 | #pragma once |
---|---|
2 | |
3 | #include <Core/Defines.h> |
4 | #include <IO/WriteBuffer.h> |
5 | #include <common/itoa.h> |
6 | #include <common/likely.h> |
7 | |
8 | /// 40 digits or 39 digits and a sign |
9 | #define WRITE_HELPERS_MAX_INT_WIDTH 40U |
10 | |
11 | namespace DB |
12 | { |
13 | |
14 | namespace detail |
15 | { |
16 | template <typename T> |
17 | void NO_INLINE writeUIntTextFallback(T x, WriteBuffer & buf) |
18 | { |
19 | char tmp[WRITE_HELPERS_MAX_INT_WIDTH]; |
20 | int len = itoa(x, tmp) - tmp; |
21 | buf.write(tmp, len); |
22 | } |
23 | } |
24 | |
25 | template <typename T> |
26 | void writeIntText(T x, WriteBuffer & buf) |
27 | { |
28 | if (likely(buf.position() + WRITE_HELPERS_MAX_INT_WIDTH < buf.buffer().end())) |
29 | buf.position() = itoa(x, buf.position()); |
30 | else |
31 | detail::writeUIntTextFallback(x, buf); |
32 | } |
33 | |
34 | } |
35 |