QTest::qWaitFor: move ceil<> to after the check
There's no reason to check whether the timer has expired after rounding the timer's native nanoseconds up to milliseconds, so delay the ceil<ms> operation to after the timer expiry check. As a drive-by, protect the std::min call from Windows macros with the parentheses trick and employ C++17 if-with-initializer. Remove the break-if-expired, as it now obviously duplicates the while exit condition. Pick-to: 6.7 Change-Id: If30421012143640c75a9a44fe711d0c1c7cd23b9 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>bb10
parent
ad2da2080c
commit
59549657a3
|
|
@ -43,11 +43,9 @@ qWaitFor(Functor predicate, QDeadlineTimer deadline = QDeadlineTimer(std::chrono
|
|||
if (predicate())
|
||||
return true;
|
||||
|
||||
const auto remaining = ceil<milliseconds>(deadline.remainingTimeAsDuration());
|
||||
if (remaining == 0ms)
|
||||
break;
|
||||
if (const auto remaining = deadline.remainingTimeAsDuration(); remaining > 0ns)
|
||||
qSleep((std::min)(10ms, ceil<milliseconds>(remaining)));
|
||||
|
||||
qSleep(std::min(10ms, remaining));
|
||||
} while (!deadline.hasExpired());
|
||||
|
||||
return predicate(); // Last chance
|
||||
|
|
|
|||
Loading…
Reference in New Issue