Index: base/time/time.h |
diff --git a/base/time/time.h b/base/time/time.h |
index 286c0738ceb4522f791a9d9cd4ac1c67f2472ae2..b0c67493a5e5800960d4ad83e36521a68cd1091a 100644 |
--- a/base/time/time.h |
+++ b/base/time/time.h |
@@ -95,10 +95,6 @@ namespace time_internal { |
BASE_EXPORT int64_t SaturatedAdd(TimeDelta delta, int64_t value); |
BASE_EXPORT int64_t SaturatedSub(TimeDelta delta, int64_t value); |
-// Clamp |value| on overflow and underflow conditions. The int64_t argument and |
-// return value are in terms of a microsecond timebase. |
-BASE_EXPORT int64_t FromCheckedNumeric(const CheckedNumeric<int64_t> value); |
- |
} // namespace time_internal |
// TimeDelta ------------------------------------------------------------------ |
@@ -205,13 +201,23 @@ class BASE_EXPORT TimeDelta { |
TimeDelta operator*(T a) const { |
CheckedNumeric<int64_t> rv(delta_); |
rv *= a; |
- return TimeDelta(time_internal::FromCheckedNumeric(rv)); |
+ if (rv.IsValid()) |
+ return TimeDelta(rv.ValueOrDie()); |
+ // Matched sign overflows. Mismatched sign underflows. |
+ if ((delta_ < 0) ^ (a < 0)) |
+ return TimeDelta(-std::numeric_limits<int64_t>::max()); |
+ return TimeDelta(std::numeric_limits<int64_t>::max()); |
} |
template<typename T> |
TimeDelta operator/(T a) const { |
CheckedNumeric<int64_t> rv(delta_); |
rv /= a; |
- return TimeDelta(time_internal::FromCheckedNumeric(rv)); |
+ if (rv.IsValid()) |
+ return TimeDelta(rv.ValueOrDie()); |
+ // Matched sign overflows. Mismatched sign underflows. |
+ if ((delta_ < 0) ^ (a <= 0)) |
Tom Sepez
2016/11/04 16:58:58
Maybe a comment about why a <= 0, it's right but n
jschuh
2016/11/04 17:14:07
Done.
|
+ return TimeDelta(-std::numeric_limits<int64_t>::max()); |
+ return TimeDelta(std::numeric_limits<int64_t>::max()); |
} |
template<typename T> |
TimeDelta& operator*=(T a) { |