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

Unified Diff: src/base/platform/time.cc

Issue 1952843002: Create TimeBase for time related classes. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 7 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
« src/base/platform/time.h ('K') | « src/base/platform/time.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/base/platform/time.cc
diff --git a/src/base/platform/time.cc b/src/base/platform/time.cc
index 6d5e538970cfd8e8b3608c196b79c361a44c4107..fed39fc9f74649d09ec8e667bec84387a4237bfe 100644
--- a/src/base/platform/time.cc
+++ b/src/base/platform/time.cc
@@ -28,6 +28,37 @@
namespace v8 {
namespace base {
+namespace time_internal {
+
+int64_t SaturatedAdd(TimeDelta delta, int64_t value) {
fmeawad 2016/05/04 23:34:21 The Saturated methods does change the functionalit
+ CheckedNumeric<int64_t> rv(delta.delta_);
+ rv += value;
+ return FromCheckedNumeric(rv);
+}
+
+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);
+}
+
+} // namespace time_internal
+
+
TimeDelta TimeDelta::FromDays(int days) {
return TimeDelta(days * Time::kMicrosecondsPerDay);
}
« src/base/platform/time.h ('K') | « src/base/platform/time.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698