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

Unified Diff: base/time/time.cc

Issue 1130953002: Revert of Fixit: Factor out common base::Time* math operator overloads. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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
« 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 9834188597d479038b7bca055d2584feea091913..bf6c998ebf8cd2dae00b08dfa08e16f011f7503f 100644
--- a/base/time/time.cc
+++ b/base/time/time.cc
@@ -97,21 +97,20 @@
return delta_;
}
-namespace time_internal {
-
-int64 SaturatedAdd(TimeDelta delta, int64 value) {
- CheckedNumeric<int64> rv(delta.delta_);
+int64 TimeDelta::SaturatedAdd(int64 value) const {
+ CheckedNumeric<int64> rv(delta_);
rv += value;
return FromCheckedNumeric(rv);
}
-int64 SaturatedSub(TimeDelta delta, int64 value) {
- CheckedNumeric<int64> rv(delta.delta_);
+int64 TimeDelta::SaturatedSub(int64 value) const {
+ CheckedNumeric<int64> rv(delta_);
rv -= value;
return FromCheckedNumeric(rv);
}
-int64 FromCheckedNumeric(const CheckedNumeric<int64> value) {
+// static
+int64 TimeDelta::FromCheckedNumeric(const CheckedNumeric<int64> value) {
if (value.IsValid())
return value.ValueUnsafe();
@@ -124,8 +123,6 @@
limit = -limit;
return value.ValueOrDefault(limit);
}
-
-} // namespace time_internal
std::ostream& operator<<(std::ostream& os, TimeDelta time_delta) {
return os << time_delta.InSecondsF() << "s";
@@ -308,12 +305,15 @@
TimeDelta tick_interval) const {
// |interval_offset| is the offset from |this| to the next multiple of
// |tick_interval| after |tick_phase|, possibly negative if in the past.
- TimeDelta interval_offset = (tick_phase - *this) % tick_interval;
+ TimeDelta interval_offset = TimeDelta::FromInternalValue(
+ (tick_phase - *this).ToInternalValue() % tick_interval.ToInternalValue());
// If |this| is exactly on the interval (i.e. offset==0), don't adjust.
// Otherwise, if |tick_phase| was in the past, adjust forward to the next
// tick after |this|.
- if (!interval_offset.is_zero() && tick_phase < *this)
+ if (interval_offset.ToInternalValue() != 0 && tick_phase < *this) {
interval_offset += tick_interval;
+ }
+
return *this + interval_offset;
}
« 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