Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2506)

Unified Diff: base/time/time.cc

Issue 2472983003: Remove usage time.cc of CheckedNumeric::validity() (Closed)
Patch Set: nit Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/time/time.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/time/time.cc
diff --git a/base/time/time.cc b/base/time/time.cc
index 3670f5575891f6eb3ffda7774a51406245f27a65..4e942015fcf578015138c7a824ea65ac6b416b8c 100644
--- a/base/time/time.cc
+++ b/base/time/time.cc
@@ -104,27 +104,23 @@ namespace time_internal {
int64_t SaturatedAdd(TimeDelta delta, int64_t value) {
CheckedNumeric<int64_t> rv(delta.delta_);
rv += value;
- return FromCheckedNumeric(rv);
+ if (rv.IsValid())
+ return rv.ValueOrDie();
+ // Positive RHS overflows. Negative RHS underflows.
+ if (value < 0)
+ return -std::numeric_limits<int64_t>::max();
+ return std::numeric_limits<int64_t>::max();
}
int64_t SaturatedSub(TimeDelta delta, int64_t value) {
CheckedNumeric<int64_t> rv(delta.delta_);
rv -= value;
- return FromCheckedNumeric(rv);
-}
-
-int64_t FromCheckedNumeric(const CheckedNumeric<int64_t> value) {
- if (value.IsValid())
- return value.ValueUnsafe();
-
- // We could return max/min but we don't really expose what the maximum delta
- // is. Instead, return max/(-max), which is something that clients can reason
- // about.
- // TODO(rvargas) crbug.com/332611: don't use internal values.
- int64_t limit = std::numeric_limits<int64_t>::max();
- if (value.validity() == internal::RANGE_UNDERFLOW)
- limit = -limit;
- return value.ValueOrDefault(limit);
+ if (rv.IsValid())
+ return rv.ValueOrDie();
+ // Negative RHS overflows. Positive RHS underflows.
+ if (value < 0)
+ return std::numeric_limits<int64_t>::max();
+ return -std::numeric_limits<int64_t>::max();
}
} // namespace time_internal
« no previous file with comments | « base/time/time.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698