From 007d207a8c2409f10a586c309d8498d576a69f52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= Date: Wed, 14 Oct 2020 12:57:30 +0200 Subject: [PATCH] qWaitFor: check predicate before sleeping MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Return immediately if processing events caused the predicate to become true. This gives us a nice speedup on tests with call qWaitForWindowExposed() or qWaitForWindowActive(), for example tst_QGraphicsView::itemsInRect_cosmeticAdjust: cocoa 1164ms -> 825ms ~30% decrease offscreen 296ms -> 15ms ~95% decrease Change-Id: Ifbab0ca662c082e7dfb609d0cb4bc1161709067b Reviewed-by: Tor Arne Vestbø Reviewed-by: Lars Knoll --- src/corelib/kernel/qtestsupport_core.h | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/corelib/kernel/qtestsupport_core.h b/src/corelib/kernel/qtestsupport_core.h index 7043ffcf0f1..04e1c50e1ce 100644 --- a/src/corelib/kernel/qtestsupport_core.h +++ b/src/corelib/kernel/qtestsupport_core.h @@ -75,14 +75,13 @@ template QCoreApplication::processEvents(QEventLoop::AllEvents); QCoreApplication::sendPostedEvents(nullptr, QEvent::DeferredDelete); - remaining = int(deadline.remainingTime()); - if (remaining > 0) - qSleep(qMin(10, remaining)); - if (predicate()) return true; remaining = int(deadline.remainingTime()); + if (remaining > 0) + qSleep(qMin(10, remaining)); + remaining = int(deadline.remainingTime()); } while (remaining > 0); return predicate(); // Last chance