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

Unified Diff: base/time/time.h

Issue 2472983003: Remove usage time.cc of CheckedNumeric::validity() (Closed)
Patch Set: wip 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 | « no previous file | base/time/time.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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) {
« no previous file with comments | « no previous file | base/time/time.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698