diff options
author | Andrei Karas <akaras@inbox.ru> | 2013-06-30 22:43:57 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2013-06-30 22:43:57 +0300 |
commit | 70db52b49c6c2764ed48caf4a115031aa9d6b694 (patch) | |
tree | a3b4b5ef594465acc73c205b605eb7b6a3672610 /src/units.cpp | |
parent | 76da58f2272e81fea5b5d05684e8eedd31325447 (diff) | |
download | mv-70db52b49c6c2764ed48caf4a115031aa9d6b694.tar.gz mv-70db52b49c6c2764ed48caf4a115031aa9d6b694.tar.bz2 mv-70db52b49c6c2764ed48caf4a115031aa9d6b694.tar.xz mv-70db52b49c6c2764ed48caf4a115031aa9d6b694.zip |
improve size() usage in units.
Diffstat (limited to 'src/units.cpp')
-rw-r--r-- | src/units.cpp | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/src/units.cpp b/src/units.cpp index 957faa998..efccca11c 100644 --- a/src/units.cpp +++ b/src/units.cpp @@ -180,7 +180,7 @@ void Units::loadUnits() static std::string formatUnit(const int value, const int type) { - UnitDescription ud = units[type]; + const UnitDescription ud = units[type]; UnitLevel ul; // Shortcut for 0; do the same for values less than 0 (for now) @@ -192,6 +192,7 @@ static std::string formatUnit(const int value, const int type) else { double amount = ud.conversion * value; + const unsigned int sz = ud.levels.size(); // If only the first level is needed, act like mix if false if (ud.mix && !ud.levels.empty() && ud.levels[1].count < amount) @@ -213,7 +214,7 @@ static std::string formatUnit(const int value, const int type) amount), pl.separator).append(pl.symbol); } - for (unsigned int i = 2; i < ud.levels.size(); i++) + for (unsigned int i = 2; i < sz; i++) { pl = ul; ul = ud.levels[i]; @@ -240,7 +241,7 @@ static std::string formatUnit(const int value, const int type) else { ul.round = 0; - for (unsigned int i = 0; i < ud.levels.size(); i++) + for (unsigned int i = 0; i < sz; i++) { ul = ud.levels[i]; if (amount < ul.count && ul.count > 0) @@ -281,18 +282,20 @@ static std::string splitNumber(std::string str, const std::string &separator) if (!str.empty()) { - while (str.size() >= 3) + size_t sz = str.size(); + while (sz >= 3) { - if (str.size() >= 6) + if (sz >= 6) { result = std::string(separator).append(str.substr( - str.size() - 3)).append(result); + sz - 3)).append(result); } else { - result = str.substr(str.size() - 3).append(result); + result = str.substr(sz - 3).append(result); } str = str.substr(0, str.size() - 3); + sz = str.size(); } if (!str.empty()) { |