Skip to content

Commit

Permalink
Revert of Revert of Fixit: Factor out common base::Time* math operato…
Browse files Browse the repository at this point in the history
…r overloads. (patchset #1 id:1 of https://codereview.chromium.org/1130953002/)

Reason for revert:
iOS_Device builder was not rebuilding certain modules dependent on changes in base::Time.  http://crbug.com/485435

Original issue's description:
> Revert of Fixit: Factor out common base::Time* math operator overloads. (patchset #2 id:40001 of https://codereview.chromium.org/1122443004/)
>
> Reason for revert:
> Broke iOS build.
>
> http://build.chromium.org/p/chromium.mac/builders/iOS_Device/builds/5621/steps/compile/logs/stdio
>
> Original issue's description:
> > Fixit: Factor out common base::Time* math operator overloads.
> >
> > This is part 1 of a 2-part change to fork base::TimeTicks into three
> > type-checked time classes (TimeTicks + ThreadTicks + TraceTicks).  The
> > forking of TimeTicks will ensure values from different clocks are not
> > erroneously being mixed together when doing time math.
> >
> > In this change, the identical comparison and math operator overloads
> > found in base::Time and base::TimeTicks are being factored-out into a
> > templated base class.  In a following change, this base class will also
> > be used to de-dupe this common functionality in the two new time
> > classes.
> >
> > BUG=467417
> >
> > Committed: https://crrev.com/7ca717095b4758cb76e53e904b775852e46d646d
> > Cr-Commit-Position: refs/heads/master@{#328696}
>
> TBR=thestig@chromium.org,miu@chromium.org
> NOPRESUBMIT=true
> NOTREECHECKS=true
> NOTRY=true
> BUG=467417
>
> Committed: https://crrev.com/a365825583412c355a449274bec70e41e992ffd7
> Cr-Commit-Position: refs/heads/master@{#328706}

TBR=thestig@chromium.org,ksakamoto@chromium.org
NOPRESUBMIT=true
BUG=467417,485435

Review URL: https://codereview.chromium.org/1128273004

Cr-Commit-Position: refs/heads/master@{#328843}
  • Loading branch information
miu-chromium authored and Commit bot committed May 7, 2015
1 parent bd6a031 commit 59fca1c
Show file tree
Hide file tree
Showing 3 changed files with 171 additions and 219 deletions.
22 changes: 11 additions & 11 deletions base/time/time.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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";
}
Expand Down Expand Up @@ -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.is_zero() && tick_phase < *this)
interval_offset += tick_interval;
}

return *this + interval_offset;
}

Expand Down
Loading

0 comments on commit 59fca1c

Please sign in to comment.