From 5b71c85706ce755e5aae5fd8e1ef75cf90561596 Mon Sep 17 00:00:00 2001 From: Gotcha Date: Mon, 13 Jul 2015 12:01:01 +0200 Subject: [PATCH] processedTimers are now stored in QSet --- src/corelib/kernel/qeventdispatcher_win.cpp | 34 ++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/src/corelib/kernel/qeventdispatcher_win.cpp b/src/corelib/kernel/qeventdispatcher_win.cpp index ccb8341..a98ad4a 100644 --- a/src/corelib/kernel/qeventdispatcher_win.cpp +++ b/src/corelib/kernel/qeventdispatcher_win.cpp @@ -700,6 +700,27 @@ QEventDispatcherWin32::~QEventDispatcherWin32() { } +struct MsgWrapper { + explicit MsgWrapper(const MSG& msg) + : hwnd(msg.hwnd), + wParam(msg.wParam), + lParam(msg.lParam) {} + + inline bool operator==(const MsgWrapper& other) const + { + return (other.wParam == wParam + && other.hwnd == hwnd + && other.lParam == lParam); + } + + HWND hwnd; + DWORD wParam; + DWORD lParam; +}; + +inline uint qHash(const MsgWrapper& msg) { return ::qHash(msg.wParam ^ (int)msg.hwnd ^ msg.lParam); } +inline uint qHash(const MsgWrapper& msg, uint seed) { return ::qHash(msg.wParam ^ (int)msg.hwnd ^ msg.lParam, seed); } + bool QEventDispatcherWin32::processEvents(QEventLoop::ProcessEventsFlags flags) { Q_D(QEventDispatcherWin32); @@ -719,7 +740,7 @@ bool QEventDispatcherWin32::processEvents(QEventLoop::ProcessEventsFlags flags) do { DWORD waitRet = 0; HANDLE pHandles[MAXIMUM_WAIT_OBJECTS - 1]; - QVarLengthArray processedTimers; + QSet processedTimers; while (!d->interrupt) { DWORD nCount = d->winEventNotifierList.count(); Q_ASSERT(nCount < MAXIMUM_WAIT_OBJECTS - 1); @@ -786,14 +807,11 @@ bool QEventDispatcherWin32::processEvents(QEventLoop::ProcessEventsFlags flags) seenWM_QT_SENDPOSTEDEVENTS = true; } else if (msg.message == WM_TIMER) { // avoid live-lock by keeping track of the timers we've already sent - bool found = false; - for (int i = 0; !found && i < processedTimers.count(); ++i) { - const MSG processed = processedTimers.constData()[i]; - found = (processed.wParam == msg.wParam && processed.hwnd == msg.hwnd && processed.lParam == msg.lParam); - } - if (found) + MsgWrapper wrapper(msg); + if (processedTimers.contains(wrapper)) continue; - processedTimers.append(msg); + + processedTimers.insert(wrapper); } else if (msg.message == WM_QUIT) { if (QCoreApplication::instance()) QCoreApplication::instance()->quit(); -- 1.9.4.msysgit.2