2013-05-04 14:51:37 +00:00
|
|
|
#pragma once
|
|
|
|
|
2019-02-26 12:30:36 +00:00
|
|
|
#include <Core/Defines.h>
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <IO/WriteBuffer.h>
|
2018-12-29 18:39:55 +00:00
|
|
|
#include <common/itoa.h>
|
2013-05-05 16:19:09 +00:00
|
|
|
|
2018-12-29 18:39:55 +00:00
|
|
|
/// 40 digits or 39 digits and a sign
|
|
|
|
#define WRITE_HELPERS_MAX_INT_WIDTH 40U
|
2013-05-04 14:51:37 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
2019-02-26 12:31:17 +00:00
|
|
|
|
2013-05-04 14:51:37 +00:00
|
|
|
namespace detail
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
template <typename T>
|
2018-12-29 18:39:55 +00:00
|
|
|
void NO_INLINE writeUIntTextFallback(T x, WriteBuffer & buf)
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
|
|
|
char tmp[WRITE_HELPERS_MAX_INT_WIDTH];
|
2018-12-29 18:39:55 +00:00
|
|
|
int len = itoa(x, tmp) - tmp;
|
|
|
|
buf.write(tmp, len);
|
2017-04-01 07:20:54 +00:00
|
|
|
}
|
2018-07-20 19:05:07 +00:00
|
|
|
}
|
|
|
|
|
2013-05-04 14:51:37 +00:00
|
|
|
template <typename T>
|
2018-12-29 18:39:55 +00:00
|
|
|
void writeIntText(T x, WriteBuffer & buf)
|
2013-05-04 14:51:37 +00:00
|
|
|
{
|
2021-01-04 18:07:52 +00:00
|
|
|
if (likely(reinterpret_cast<intptr_t>(buf.position()) + WRITE_HELPERS_MAX_INT_WIDTH < reinterpret_cast<intptr_t>(buf.buffer().end())))
|
2018-12-29 18:39:55 +00:00
|
|
|
buf.position() = itoa(x, buf.position());
|
|
|
|
else
|
|
|
|
detail::writeUIntTextFallback(x, buf);
|
2013-05-04 14:51:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|