qWaitFor: check predicate before sleeping
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ø <tor.arne.vestbo@qt.io> Reviewed-by: Lars Knoll <lars.knoll@qt.io>
This commit is contained in:
parent
48758816db
commit
007d207a8c
@ -75,14 +75,13 @@ template <typename Functor>
|
|||||||
QCoreApplication::processEvents(QEventLoop::AllEvents);
|
QCoreApplication::processEvents(QEventLoop::AllEvents);
|
||||||
QCoreApplication::sendPostedEvents(nullptr, QEvent::DeferredDelete);
|
QCoreApplication::sendPostedEvents(nullptr, QEvent::DeferredDelete);
|
||||||
|
|
||||||
remaining = int(deadline.remainingTime());
|
|
||||||
if (remaining > 0)
|
|
||||||
qSleep(qMin(10, remaining));
|
|
||||||
|
|
||||||
if (predicate())
|
if (predicate())
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
remaining = int(deadline.remainingTime());
|
remaining = int(deadline.remainingTime());
|
||||||
|
if (remaining > 0)
|
||||||
|
qSleep(qMin(10, remaining));
|
||||||
|
remaining = int(deadline.remainingTime());
|
||||||
} while (remaining > 0);
|
} while (remaining > 0);
|
||||||
|
|
||||||
return predicate(); // Last chance
|
return predicate(); // Last chance
|
||||||
|
Loading…
x
Reference in New Issue
Block a user