Bug 1026803 part 3 - Make some simplifications to SystemTimeConverter; r=karlt

This patch exploits the fact that the underlying Time type is an unsigned
integer to simplify some of the overflow checks in SystemTimeConvert by relying
on unsigned integer overflow behavior, which, unlike signed integer overflow, is
well-defined.

--HG--
extra : rebase_source : e21f865e1ed22e1d3adc5e835e052cb9f80b9beb
This commit is contained in:
Brian Birtles 2015-02-19 14:06:01 +09:00
Родитель d6dfa32cc0
Коммит 7dc9a3e6ae
1 изменённых файлов: 6 добавлений и 11 удалений

Просмотреть файл

@ -59,17 +59,14 @@ public:
// bit past the reference timestamp (again less than half the range).
// In that case we should adjust the reference time so it is the
// earliest time.
if (aTime < mReferenceTime &&
mReferenceTime - aTime < kTimeHalfRange &&
Time timeSinceReference = aTime - mReferenceTime;
if (timeSinceReference > kTimeHalfRange &&
roughlyNow - mReferenceTimeStamp <
TimeDuration::FromMilliseconds(kTimeHalfRange)) {
UpdateReferenceTime(aTime, aGetCurrentTimeFunc);
timeSinceReference = aTime - mReferenceTime;
}
double timeSinceReference =
mReferenceTime <= aTime
? aTime - mReferenceTime
: static_cast<double>(kTimeRange) + aTime - mReferenceTime;
TimeStamp timestamp =
mReferenceTimeStamp + TimeDuration::FromMilliseconds(timeSinceReference);
@ -77,7 +74,8 @@ public:
// time so we extend timestamp as needed.
double timesWrapped =
(roughlyNow - mReferenceTimeStamp).ToMilliseconds() / kTimeRange;
int32_t cyclesToAdd = static_cast<int32_t>(timesWrapped); // floor
int32_t cyclesToAdd =
static_cast<int32_t>(timesWrapped); // Round towards zero
// There is some imprecision in the above calculation since we are using
// TimeStamp::NowLoRes and mReferenceTime and mReferenceTimeStamp may not
@ -115,10 +113,7 @@ private:
mReferenceTime = aTime;
Time currentTime = aGetCurrentTimeFunc();
TimeStamp currentTimeStamp = TimeStamp::Now();
double timeSinceReference =
aTime <= currentTime
? currentTime - aTime
: static_cast<double>(kTimeRange) + currentTime - aTime;
Time timeSinceReference = currentTime - aTime;
mReferenceTimeStamp =
currentTimeStamp - TimeDuration::FromMilliseconds(timeSinceReference);
}