Skip to content

Commit

Permalink
try to avoid floating point conversion and mult via (hopefully well p…
Browse files Browse the repository at this point in the history
…redicted) branch
  • Loading branch information
Swiftb0y committed Aug 29, 2023
1 parent 45653b4 commit f90452c
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/util/highresolution_monotonic_clock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@

// mac/unix code heavily copied from QElapsedTimer

#if false
#if defined(Q_OS_MAC)

static double multiplier = 0.0;
static double getMultiplier() {
Expand All @@ -74,15 +74,19 @@ static double getMultiplier() {
}

static std::chrono::nanoseconds absoluteToNSecs(qint64 cpuTime) {
return std::chrono::nanoseconds(static_cast<double>(cpuTime) * getMultiplier());
double mult = getMultiplier();
if (mult == 1.0) [[likely]] {
return std::chrono::nanoseconds(cpuTime);
} else {
return std::chrono::nanoseconds(static_cast<double>(cpuTime) * mult);
}
}

auto HighResolutionMonotonicClockFallback::now() noexcept -> time_point {
return time_point(absoluteToNSecs(mach_absolute_time()));
}

#elif defined(Q_OS_UNIX) || defined(Q_OS_MAC)

#elif defined(Q_OS_UNIX)
// #if (_POSIX_MONOTONIC_CLOCK - 0 != 0)
// static std::atomic<bool> monotonicClockChecked = true;
// static std::atomic<bool> monotonicClockAvailable = _POSIX_MONOTONIC_CLOCK > 0;
Expand Down

0 comments on commit f90452c

Please sign in to comment.