MCPcopy Create free account
hub / github.com/apache/impala / ToString

Method ToString

be/src/gutil/strings/human_readable.cc:114–139  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

112}
113
114string HumanReadableNumBytes::ToString(int64 num_bytes) {
115 if (num_bytes == kint64min) {
116 // Special case for number with not representable nagation.
117 return "-8E";
118 }
119
120 const char *neg_str = GetNegStr(&num_bytes);
121
122 // Special case for bytes.
123 if (num_bytes < GG_LONGLONG(1024)) {
124 // No fractions for bytes.
125 return StringPrintf("%s%" PRId64 "B", neg_str, num_bytes);
126 }
127
128 static const char units[] = "KMGTPE"; // int64 only goes up to E.
129 const char* unit = units;
130 while (num_bytes >= GG_LONGLONG(1024) * GG_LONGLONG(1024)) {
131 num_bytes /= GG_LONGLONG(1024);
132 ++unit;
133 CHECK(unit < units + arraysize(units));
134 }
135
136 return StringPrintf(((*unit == 'K')
137 ? "%s%.1f%c"
138 : "%s%.2f%c"), neg_str, num_bytes / 1024.0, *unit);
139}
140
141string HumanReadableNumBytes::ToStringWithoutRounding(int64 num_bytes) {
142 if (num_bytes == kint64min) {

Callers 5

operator()Method · 0.45
operator()Method · 0.45
LiteralMethod · 0.45
AnyOfMethod · 0.45
ShellEscapeFunction · 0.45

Calls 4

GetNegStrFunction · 0.85
StringPrintfFunction · 0.85
StringAppendFFunction · 0.85
ToStringFunction · 0.50

Tested by

no test coverage detected