From fbd569978605f4cb2e92ea7a75ec6c1130abc7a9 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Thu, 6 Jun 2019 00:15:09 +0800 Subject: [PATCH 1/3] Use switch statement --- src/base/utils/misc.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/base/utils/misc.cpp b/src/base/utils/misc.cpp index 39c066f75..c10c5fd2e 100644 --- a/src/base/utils/misc.cpp +++ b/src/base/utils/misc.cpp @@ -250,13 +250,20 @@ QString Utils::Misc::friendlyUnit(const qint64 bytesValue, const bool isSpeed) + unitString(unit, isSpeed); } -int Utils::Misc::friendlyUnitPrecision(SizeUnit unit) +int Utils::Misc::friendlyUnitPrecision(const SizeUnit unit) { // friendlyUnit's number of digits after the decimal point - if (unit == SizeUnit::Byte) return 0; - if (unit <= SizeUnit::MebiByte) return 1; - if (unit == SizeUnit::GibiByte) return 2; - return 3; + switch (unit) { + case SizeUnit::Byte: + return 0; + case SizeUnit::KibiByte: + case SizeUnit::MebiByte: + return 1; + case SizeUnit::GibiByte: + return 2; + default: + return 3; + } } qlonglong Utils::Misc::sizeInBytes(qreal size, const Utils::Misc::SizeUnit unit) From 431e7179ac9dcd4b5898ef5cbf90a755708b3c51 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Thu, 6 Jun 2019 00:20:57 +0800 Subject: [PATCH 2/3] Remove redundant variable --- src/base/utils/misc.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/base/utils/misc.cpp b/src/base/utils/misc.cpp index c10c5fd2e..6514abf8f 100644 --- a/src/base/utils/misc.cpp +++ b/src/base/utils/misc.cpp @@ -80,13 +80,13 @@ namespace if (sizeInBytes < 0) return false; int i = 0; - auto rawVal = static_cast(sizeInBytes); + val = static_cast(sizeInBytes); - while ((rawVal >= 1024.) && (i <= static_cast(Utils::Misc::SizeUnit::ExbiByte))) { - rawVal /= 1024.; + while ((val >= 1024.) && (i <= static_cast(Utils::Misc::SizeUnit::ExbiByte))) { + val /= 1024.; ++i; } - val = rawVal; + unit = static_cast(i); return true; } From 7c9309aa522f15f70a5666de23e7d1cd711cf79c Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Fri, 7 Jun 2019 14:11:09 +0800 Subject: [PATCH 3/3] Fix wrong indentation --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 7c5392eff..d7bd38a3e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -147,7 +147,7 @@ install: sudo dpkg -i "$HOME/travis/deb/libtorrent-rasterbar-dev_1.2.x_amd64.deb" "$HOME/travis/deb/libtorrent-rasterbar10_1.2.x_amd64.deb" fi - - | + - | if [ "$libt_branch" = "RC_1_1" ] && [ "$TRAVIS_OS_NAME" = "osx" ]; then wget https://builds.shiki.hu/travis/brew/1_1/version if ! cmp --quiet "version" "$HOME/travis/brew/1_1/version" ; then