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 |