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

Unified Diff: base/time/time_win.cc

Issue 429743002: Make QPCValueToMicroseconds faster in case the value is less than 44 bits (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Typo Created 6 years, 5 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
Index: base/time/time_win.cc
diff --git a/base/time/time_win.cc b/base/time/time_win.cc
index cf7be687d2e5a0b292414796f1b3c25e2535f518..5fa899d1f97f69be69d1df65ba854565d7240b53 100644
--- a/base/time/time_win.cc
+++ b/base/time/time_win.cc
@@ -393,11 +393,14 @@ class HighResNowSingleton {
int64 QPCValueToMicroseconds(LONGLONG qpc_value) {
if (!ticks_per_second_)
return 0;
-
- // Intentionally calculate microseconds in a round about manner to avoid
- // overflow and precision issues. Think twice before simplifying!
+ // If the QPC Value is below the overflow threshold, we proceed with
+ // simple multiply and divide.
+ if (qpc_value < Time::kQPCOverflowThreshold)
+ return qpc_value * Time::kMicrosecondsPerSecond / ticks_per_second_;
+ // Otherwise, calculate microseconds in a round about manner to avoid
+ // overflow and precision issues.
int64 whole_seconds = qpc_value / ticks_per_second_;
- int64 leftover_ticks = qpc_value % ticks_per_second_;
+ int64 leftover_ticks = qpc_value - (whole_seconds * ticks_per_second_);
int64 microseconds = (whole_seconds * Time::kMicrosecondsPerSecond) +
((leftover_ticks * Time::kMicrosecondsPerSecond) /
ticks_per_second_);
@@ -447,7 +450,8 @@ NowFunction now_function = RolloverProtectedNow;
bool CPUReliablySupportsHighResTime() {
base::CPU cpu;
- if (!cpu.has_non_stop_time_stamp_counter())
+ if (!cpu.has_non_stop_time_stamp_counter() ||
+ !GetHighResNowSingleton()->IsUsingHighResClock())
return false;
if (IsBuggyAthlon(cpu))

Powered by Google App Engine
This is Rietveld 408576698