diff options
Diffstat (limited to 'absl/time/duration.cc')
-rw-r--r-- | absl/time/duration.cc | 39 |
1 files changed, 22 insertions, 17 deletions
diff --git a/absl/time/duration.cc b/absl/time/duration.cc index 911e80f8..b915d749 100644 --- a/absl/time/duration.cc +++ b/absl/time/duration.cc @@ -407,16 +407,18 @@ int64_t IDivDuration(bool satq, const Duration num, const Duration den, Duration& Duration::operator+=(Duration rhs) { if (time_internal::IsInfiniteDuration(*this)) return *this; if (time_internal::IsInfiniteDuration(rhs)) return *this = rhs; - const int64_t orig_rep_hi = rep_hi_; - rep_hi_ = - DecodeTwosComp(EncodeTwosComp(rep_hi_) + EncodeTwosComp(rhs.rep_hi_)); + const int64_t orig_rep_hi = rep_hi_.Get(); + rep_hi_ = DecodeTwosComp(EncodeTwosComp(rep_hi_.Get()) + + EncodeTwosComp(rhs.rep_hi_.Get())); if (rep_lo_ >= kTicksPerSecond - rhs.rep_lo_) { - rep_hi_ = DecodeTwosComp(EncodeTwosComp(rep_hi_) + 1); + rep_hi_ = DecodeTwosComp(EncodeTwosComp(rep_hi_.Get()) + 1); rep_lo_ -= kTicksPerSecond; } rep_lo_ += rhs.rep_lo_; - if (rhs.rep_hi_ < 0 ? rep_hi_ > orig_rep_hi : rep_hi_ < orig_rep_hi) { - return *this = rhs.rep_hi_ < 0 ? -InfiniteDuration() : InfiniteDuration(); + if (rhs.rep_hi_.Get() < 0 ? rep_hi_.Get() > orig_rep_hi + : rep_hi_.Get() < orig_rep_hi) { + return *this = + rhs.rep_hi_.Get() < 0 ? -InfiniteDuration() : InfiniteDuration(); } return *this; } @@ -424,18 +426,21 @@ Duration& Duration::operator+=(Duration rhs) { Duration& Duration::operator-=(Duration rhs) { if (time_internal::IsInfiniteDuration(*this)) return *this; if (time_internal::IsInfiniteDuration(rhs)) { - return *this = rhs.rep_hi_ >= 0 ? -InfiniteDuration() : InfiniteDuration(); + return *this = rhs.rep_hi_.Get() >= 0 ? -InfiniteDuration() + : InfiniteDuration(); } - const int64_t orig_rep_hi = rep_hi_; - rep_hi_ = - DecodeTwosComp(EncodeTwosComp(rep_hi_) - EncodeTwosComp(rhs.rep_hi_)); + const int64_t orig_rep_hi = rep_hi_.Get(); + rep_hi_ = DecodeTwosComp(EncodeTwosComp(rep_hi_.Get()) - + EncodeTwosComp(rhs.rep_hi_.Get())); if (rep_lo_ < rhs.rep_lo_) { - rep_hi_ = DecodeTwosComp(EncodeTwosComp(rep_hi_) - 1); + rep_hi_ = DecodeTwosComp(EncodeTwosComp(rep_hi_.Get()) - 1); rep_lo_ += kTicksPerSecond; } rep_lo_ -= rhs.rep_lo_; - if (rhs.rep_hi_ < 0 ? rep_hi_ < orig_rep_hi : rep_hi_ > orig_rep_hi) { - return *this = rhs.rep_hi_ >= 0 ? -InfiniteDuration() : InfiniteDuration(); + if (rhs.rep_hi_.Get() < 0 ? rep_hi_.Get() < orig_rep_hi + : rep_hi_.Get() > orig_rep_hi) { + return *this = rhs.rep_hi_.Get() >= 0 ? -InfiniteDuration() + : InfiniteDuration(); } return *this; } @@ -446,7 +451,7 @@ Duration& Duration::operator-=(Duration rhs) { Duration& Duration::operator*=(int64_t r) { if (time_internal::IsInfiniteDuration(*this)) { - const bool is_neg = (r < 0) != (rep_hi_ < 0); + const bool is_neg = (r < 0) != (rep_hi_.Get() < 0); return *this = is_neg ? -InfiniteDuration() : InfiniteDuration(); } return *this = ScaleFixed<SafeMultiply>(*this, r); @@ -454,7 +459,7 @@ Duration& Duration::operator*=(int64_t r) { Duration& Duration::operator*=(double r) { if (time_internal::IsInfiniteDuration(*this) || !IsFinite(r)) { - const bool is_neg = (std::signbit(r) != 0) != (rep_hi_ < 0); + const bool is_neg = std::signbit(r) != (rep_hi_.Get() < 0); return *this = is_neg ? -InfiniteDuration() : InfiniteDuration(); } return *this = ScaleDouble<std::multiplies>(*this, r); @@ -462,7 +467,7 @@ Duration& Duration::operator*=(double r) { Duration& Duration::operator/=(int64_t r) { if (time_internal::IsInfiniteDuration(*this) || r == 0) { - const bool is_neg = (r < 0) != (rep_hi_ < 0); + const bool is_neg = (r < 0) != (rep_hi_.Get() < 0); return *this = is_neg ? -InfiniteDuration() : InfiniteDuration(); } return *this = ScaleFixed<std::divides>(*this, r); @@ -470,7 +475,7 @@ Duration& Duration::operator/=(int64_t r) { Duration& Duration::operator/=(double r) { if (time_internal::IsInfiniteDuration(*this) || !IsValidDivisor(r)) { - const bool is_neg = (std::signbit(r) != 0) != (rep_hi_ < 0); + const bool is_neg = std::signbit(r) != (rep_hi_.Get() < 0); return *this = is_neg ? -InfiniteDuration() : InfiniteDuration(); } return *this = ScaleDouble<std::divides>(*this, r); |