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

Unified Diff: base/time/time.cc

Issue 1028333002: Chromium -> Mojo roll. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 9 months 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') | base/time/time_unittest.cc » ('j') | 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 951f7ba9e0a18d75963d364c149cf738d10663e4..321323b7cdbdb62640f7b23ad6e72073cd4eb948 100644
--- a/base/time/time.cc
+++ b/base/time/time.cc
@@ -97,6 +97,33 @@ int64 TimeDelta::InMicroseconds() const {
return delta_;
}
+int64 TimeDelta::SaturatedAdd(int64 value) const {
+ CheckedNumeric<int64> rv(delta_);
+ rv += value;
+ return FromCheckedNumeric(rv);
+}
+
+int64 TimeDelta::SaturatedSub(int64 value) const {
+ CheckedNumeric<int64> rv(delta_);
+ rv -= value;
+ return FromCheckedNumeric(rv);
+}
+
+// static
+int64 TimeDelta::FromCheckedNumeric(const CheckedNumeric<int64> 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 limit = std::numeric_limits<int64>::max();
+ if (value.validity() == internal::RANGE_UNDERFLOW)
+ limit = -limit;
+ return value.ValueOrDefault(limit);
+}
+
std::ostream& operator<<(std::ostream& os, TimeDelta time_delta) {
return os << time_delta.InSecondsF() << "s";
}
« no previous file with comments | « base/time/time.h ('k') | base/time/time_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698