Index: base/time/time.cc |
diff --git a/base/time/time.cc b/base/time/time.cc |
index bf6c998ebf8cd2dae00b08dfa08e16f011f7503f..153a7cc714930d7c32811d021d7b4dfe1cf832a2 100644 |
--- a/base/time/time.cc |
+++ b/base/time/time.cc |
@@ -97,20 +97,21 @@ int64 TimeDelta::InMicroseconds() const { |
return delta_; |
} |
-int64 TimeDelta::SaturatedAdd(int64 value) const { |
- CheckedNumeric<int64> rv(delta_); |
+namespace time_internal { |
+ |
+int64 SaturatedAdd(TimeDelta delta, int64 value) { |
+ CheckedNumeric<int64> rv(delta.delta_); |
rv += value; |
return FromCheckedNumeric(rv); |
} |
-int64 TimeDelta::SaturatedSub(int64 value) const { |
- CheckedNumeric<int64> rv(delta_); |
+int64 SaturatedSub(TimeDelta delta, int64 value) { |
+ CheckedNumeric<int64> rv(delta.delta_); |
rv -= value; |
return FromCheckedNumeric(rv); |
} |
-// static |
-int64 TimeDelta::FromCheckedNumeric(const CheckedNumeric<int64> value) { |
+int64 FromCheckedNumeric(const CheckedNumeric<int64> value) { |
if (value.IsValid()) |
return value.ValueUnsafe(); |
@@ -124,6 +125,8 @@ int64 TimeDelta::FromCheckedNumeric(const CheckedNumeric<int64> value) { |
return value.ValueOrDefault(limit); |
} |
+} // namespace time_internal |
+ |
std::ostream& operator<<(std::ostream& os, TimeDelta time_delta) { |
return os << time_delta.InSecondsF() << "s"; |
} |
@@ -305,15 +308,12 @@ TimeTicks TimeTicks::SnappedToNextTick(TimeTicks tick_phase, |
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 = TimeDelta::FromInternalValue( |
- (tick_phase - *this).ToInternalValue() % tick_interval.ToInternalValue()); |
+ TimeDelta interval_offset = (tick_phase - *this) % tick_interval; |
// 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.ToInternalValue() != 0 && tick_phase < *this) { |
+ if (interval_offset != base::TimeDelta() && tick_phase < *this) |
interval_offset += tick_interval; |
- } |
- |
return *this + interval_offset; |
} |
@@ -327,6 +327,16 @@ std::ostream& operator<<(std::ostream& os, TimeTicks time_ticks) { |
return os << as_time_delta.InMicroseconds() << " bogo-microseconds"; |
} |
+std::ostream& operator<<(std::ostream& os, ThreadTicks thread_ticks) { |
+ const TimeDelta as_time_delta = thread_ticks - ThreadTicks(); |
+ return os << as_time_delta.InMicroseconds() << " bogo-thread-microseconds"; |
+} |
+ |
+std::ostream& operator<<(std::ostream& os, TraceTicks trace_ticks) { |
+ const TimeDelta as_time_delta = trace_ticks - TraceTicks(); |
+ return os << as_time_delta.InMicroseconds() << " bogo-trace-microseconds"; |
+} |
+ |
// Time::Exploded ------------------------------------------------------------- |
inline bool is_in_range(int value, int lo, int hi) { |