Changed Bytes operators to take unsigned integers. The multiplication and division operators for `Bytes` take a `double` argument. Changing this to an unsigned integer removes the implicit `double` to `uint64_t` casting. These operators are currently only used in tests.
Review: https://reviews.apache.org/r/52652/ Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/4c79b393 Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/4c79b393 Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/4c79b393 Branch: refs/heads/master Commit: 4c79b39330e38c865c5e9812e5911f598c1710fd Parents: 842c4cf Author: Joseph Wu <jos...@mesosphere.io> Authored: Wed Nov 23 13:08:42 2016 -0800 Committer: Joseph Wu <josep...@apache.org> Committed: Wed Nov 23 13:08:42 2016 -0800 ---------------------------------------------------------------------- 3rdparty/stout/include/stout/bytes.hpp | 28 ++++------------------------ 3rdparty/stout/tests/bytes_tests.cpp | 4 ++-- 2 files changed, 6 insertions(+), 26 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/4c79b393/3rdparty/stout/include/stout/bytes.hpp ---------------------------------------------------------------------- diff --git a/3rdparty/stout/include/stout/bytes.hpp b/3rdparty/stout/include/stout/bytes.hpp index 9debe2f..98223db 100644 --- a/3rdparty/stout/include/stout/bytes.hpp +++ b/3rdparty/stout/include/stout/bytes.hpp @@ -97,24 +97,14 @@ public: return *this; } - Bytes& operator*=(double multiplier) + Bytes& operator*=(uint64_t multiplier) { - if (multiplier < 0) { - ABORT("Multiplying Bytes by negative multiplier " - "'" + stringify(multiplier) + "'"); - } - value *= multiplier; return *this; } - Bytes& operator/=(double divisor) + Bytes& operator/=(uint64_t divisor) { - if (divisor < 0) { - ABORT("Dividing Bytes by negative divisor " - "'" + stringify(divisor) + "'"); - } - value /= divisor; return *this; } @@ -194,26 +184,16 @@ inline Bytes operator-(const Bytes& lhs, const Bytes& rhs) } -inline Bytes operator*(const Bytes& lhs, double multiplier) +inline Bytes operator*(const Bytes& lhs, uint64_t multiplier) { - if (multiplier < 0) { - ABORT("Multiplying Bytes by negative multiplier " - "'" + stringify(multiplier) + "'"); - } - Bytes result = lhs; result *= multiplier; return result; } -inline Bytes operator/(const Bytes& lhs, double divisor) +inline Bytes operator/(const Bytes& lhs, uint64_t divisor) { - if (divisor < 0) { - ABORT("Dividing Bytes by negative divisor " - "'" + stringify(divisor) + "'"); - } - Bytes result = lhs; result /= divisor; return result; http://git-wip-us.apache.org/repos/asf/mesos/blob/4c79b393/3rdparty/stout/tests/bytes_tests.cpp ---------------------------------------------------------------------- diff --git a/3rdparty/stout/tests/bytes_tests.cpp b/3rdparty/stout/tests/bytes_tests.cpp index 9d32ea1..1e175d7 100644 --- a/3rdparty/stout/tests/bytes_tests.cpp +++ b/3rdparty/stout/tests/bytes_tests.cpp @@ -44,9 +44,9 @@ TEST(BytesTest, Arithmetic) EXPECT_EQ(Terabytes(1), Gigabytes(512) + Gigabytes(512)); EXPECT_EQ(Terabytes(1), Terabytes(2) - Terabytes(1)); - EXPECT_EQ(Terabytes(1), Gigabytes(1) * 1024); + EXPECT_EQ(Terabytes(1), Gigabytes(1) * 1024u); - EXPECT_EQ(Gigabytes(1), Terabytes(1) / 1024); + EXPECT_EQ(Gigabytes(1), Terabytes(1) / 1024u); }