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>
|
2019-03-13 13:58:04 +00:00
|
|
|
#include <common/likely.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
|
|
|
{
|
2018-12-29 18:39:55 +00:00
|
|
|
if (likely(buf.position() + WRITE_HELPERS_MAX_INT_WIDTH < buf.buffer().end()))
|
|
|
|
buf.position() = itoa(x, buf.position());
|
|
|
|
else
|
|
|
|
detail::writeUIntTextFallback(x, buf);
|
2013-05-04 14:51:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|