From 59549657a3699b5ea963b7cdc0bd69f08ab6513a Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Mon, 11 Mar 2024 11:42:35 +0100 Subject: [PATCH] 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 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 Reviewed-by: Thiago Macieira --- src/corelib/kernel/qtestsupport_core.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/corelib/kernel/qtestsupport_core.h b/src/corelib/kernel/qtestsupport_core.h index bf90a07b87..ac58898188 100644 --- a/src/corelib/kernel/qtestsupport_core.h +++ b/src/corelib/kernel/qtestsupport_core.h @@ -43,11 +43,9 @@ qWaitFor(Functor predicate, QDeadlineTimer deadline = QDeadlineTimer(std::chrono if (predicate()) return true; - const auto remaining = ceil(deadline.remainingTimeAsDuration()); - if (remaining == 0ms) - break; + if (const auto remaining = deadline.remainingTimeAsDuration(); remaining > 0ns) + qSleep((std::min)(10ms, ceil(remaining))); - qSleep(std::min(10ms, remaining)); } while (!deadline.hasExpired()); return predicate(); // Last chance