From 36920de1711901ba7b5b19e890ae0ff739409767 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Mon, 6 Aug 2018 13:31:53 -0500 Subject: [PATCH] include/types: render SI units adjacent to number Make out << si_u_t(foo) << " objects" result in strings like "0 objects" "123k objects" "3M objects" instead of "0 objects" "0 k objects" "3 M objects" Signed-off-by: Sage Weil --- src/include/types.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/include/types.h b/src/include/types.h index f239823dde022..af3b8d18039bb 100644 --- a/src/include/types.h +++ b/src/include/types.h @@ -363,11 +363,11 @@ namespace { char buffer[32]; if (index == 0) { - (void) snprintf(buffer, sizeof(buffer), "%" PRId64 " %s", n, u); + (void) snprintf(buffer, sizeof(buffer), "%" PRId64 "%s", n, u); } else if ((v % mult) == 0) { // If this is an even multiple of the base, always display // without any decimal fraction. - (void) snprintf(buffer, sizeof(buffer), "%" PRId64 " %s", n, u); + (void) snprintf(buffer, sizeof(buffer), "%" PRId64 "%s", n, u); } else { // We want to choose a precision that reflects the best choice // for fitting in 5 characters. This can get rather tricky when @@ -378,7 +378,7 @@ namespace { // easier just to try each combination in turn. int i; for (i = 2; i >= 0; i--) { - if (snprintf(buffer, sizeof(buffer), "%.*f %s", i, + if (snprintf(buffer, sizeof(buffer), "%.*f%s", i, static_cast(v) / mult, u) <= 7) break; } @@ -429,7 +429,7 @@ inline ostream& operator<<(ostream& out, const byte_u_t& b) { uint64_t n = b.v; int index = 0; - const char* u[] = {"B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB"}; + const char* u[] = {" B", " KiB", " MiB", " GiB", " TiB", " PiB", " EiB"}; while (n >= 1024 && index < 7) { n /= 1024; -- 2.39.5