MCPcopy Create free account
hub / github.com/ByConity/ByConity / formatReadable

Function formatReadable

src/Common/formatReadable.cpp:18–35  ·  view source on GitHub ↗

I wanted to make this ALWAYS_INLINE to prevent flappy performance tests, but GCC complains it may not be inlined.

Source from the content-addressed store, hash-verified

16// I wanted to make this ALWAYS_INLINE to prevent flappy performance tests,
17// but GCC complains it may not be inlined.
18static void formatReadable(double size, DB::WriteBuffer & out,
19 int precision, const char ** units, size_t units_size, double delimiter)
20{
21 size_t i = 0;
22 for (; i + 1 < units_size && fabs(size) >= delimiter; ++i)
23 size /= delimiter;
24
25 DB::DoubleConverter<false>::BufferType buffer;
26 double_conversion::StringBuilder builder{buffer, sizeof(buffer)};
27
28 const auto result = DB::DoubleConverter<false>::instance().ToFixed(size, precision, &builder);
29
30 if (!result)
31 throw DB::Exception("Cannot print float or double number", DB::ErrorCodes::CANNOT_PRINT_FLOAT_OR_DOUBLE_NUMBER);
32
33 out.write(buffer, builder.position());
34 writeCString(units[i], out);
35}
36
37
38void formatReadableSizeWithBinarySuffix(double value, DB::WriteBuffer & out, int precision)

Calls 3

ExceptionClass · 0.70
writeMethod · 0.45
positionMethod · 0.45

Tested by

no test coverage detected