Skip to content

Commit 9958b8e

Browse files
committed
[GR-69576] Use KiB MiB GiB consistently in Native Image output
1 parent cd9de56 commit 9958b8e

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ByteFormattingUtil.java

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,33 +25,29 @@
2525
package com.oracle.svm.hosted;
2626

2727
public class ByteFormattingUtil {
28-
private static final double BYTES_TO_KB = 1000d;
29-
private static final double BYTES_TO_MB = 1000d * 1000d;
30-
private static final double BYTES_TO_GB = 1000d * 1000d * 1000d;
28+
private static final long KiB_TO_BYTES = 1024L;
29+
private static final long MiB_TO_BYTES = 1024L * KiB_TO_BYTES;
30+
private static final long GiB_TO_BYTES = 1024L * MiB_TO_BYTES;
3131

3232
public static String bytesToHuman(long bytes) {
3333
assert bytes >= 0;
34-
if (bytes < BYTES_TO_KB) {
35-
return plainBytes(bytes, "B");
36-
} else if (bytes < BYTES_TO_MB) {
37-
return toHuman(bytes / BYTES_TO_KB, "kB");
38-
} else if (bytes < BYTES_TO_GB) {
39-
return toHuman(bytes / BYTES_TO_MB, "MB");
34+
if (bytes < KiB_TO_BYTES) {
35+
return bytes + "B";
36+
} else if (bytes < MiB_TO_BYTES) {
37+
return toHuman((double) bytes / KiB_TO_BYTES, "KiB");
38+
} else if (bytes < GiB_TO_BYTES) {
39+
return toHuman((double) bytes / MiB_TO_BYTES, "MiB");
4040
} else {
4141
return bytesToHumanGB(bytes);
4242
}
4343
}
4444

4545
public static String bytesToHumanGB(long bytes) {
46-
return toHuman(bytes / BYTES_TO_GB, "GB");
46+
return toHuman((double) bytes / GiB_TO_BYTES, "GiB");
4747
}
4848

4949
private static String toHuman(double value, String unit) {
5050
return "%.2f%s".formatted(value, unit);
5151
}
5252

53-
private static String plainBytes(long value, String unit) {
54-
assert 0 <= value && value < BYTES_TO_KB;
55-
return "%d%s".formatted(value, unit);
56-
}
5753
}

0 commit comments

Comments
 (0)