aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorAlexander Tkachev2019-07-24 00:45:20 +0700
committerMatan Bareket2019-07-30 14:51:41 -0400
commit7fc6477ce2d1001ab5111a16d2a6b408951a0b59 (patch)
tree8b770cfe80bc9e63ca6f3d2f2c9365e35032c9fb /common
parent16d97b6948326eb07e49b57a567b469493fa1916 (diff)
downloadscummvm-rg350-7fc6477ce2d1001ab5111a16d2a6b408951a0b59.tar.gz
scummvm-rg350-7fc6477ce2d1001ab5111a16d2a6b408951a0b59.tar.bz2
scummvm-rg350-7fc6477ce2d1001ab5111a16d2a6b408951a0b59.zip
COMMON: Update getHumanReadableBytes() in util.h
Function now casts bytes (as <1024) to unsigned long int to correspond "%lu" format string. For consistency, KB are now printed as floating number. Finally, it looks like double is pretty precise to be used in comparisons, so I made the function a little bit shorter.
Diffstat (limited to 'common')
-rw-r--r--common/util.cpp25
1 files changed, 9 insertions, 16 deletions
diff --git a/common/util.cpp b/common/util.cpp
index 7c309ce364..4b7537f8ec 100644
--- a/common/util.cpp
+++ b/common/util.cpp
@@ -168,38 +168,31 @@ bool isGraph(int c) {
Common::String getHumanReadableBytes(uint64 bytes, Common::String &unitsOut) {
- Common::String result = Common::String::format("%lu", bytes);
- unitsOut = "B";
-
- if (bytes >= 1024) {
- bytes /= 1024;
- result = Common::String::format("%lu", bytes);
- unitsOut = "KB";
+ if (bytes < 1024) {
+ unitsOut = "B";
+ return Common::String::format("%lu", (unsigned long int)bytes);
}
- double floating = bytes;
+ double floating = bytes / 1024.0;
+ unitsOut = "KB";
- if (bytes >= 1024) {
- bytes /= 1024;
+ if (floating >= 1024) {
floating /= 1024.0;
unitsOut = "MB";
}
- if (bytes >= 1024) {
- bytes /= 1024;
+ if (floating >= 1024) {
floating /= 1024.0;
unitsOut = "GB";
}
- if (bytes >= 1024) { // woah
- bytes /= 1024;
+ if (floating >= 1024) { // woah
floating /= 1024.0;
unitsOut = "TB";
}
// print one digit after floating point
- result = Common::String::format("%.1f", floating);
- return result;
+ return Common::String::format("%.1f", floating);
}
} // End of namespace Common