aboutsummaryrefslogtreecommitdiffstats
path: root/src/webchannel/signalhandler_p.h
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2022-12-27 23:23:12 +0100
committerMarc Mutz <marc.mutz@qt.io>2023-08-04 22:43:15 +0200
commit95c5c901d16edd7fb5a83767258c6c88bb6bfc8d (patch)
treeed8bd5747413e213d05f25a3d6a5cb15525eff39 /src/webchannel/signalhandler_p.h
parent8e8b51abfdd891e969eb2534b70ed1bb52573db8 (diff)
SignalHandler: eradicate the last two Q_FOREACH in the class
Use a "consume-loop" over m_connectionsCounter to insulate the loops from potenial re-entry into the class (disconnectNotify() calls unknown code). Yes, this sheds the QHash's capacity(). If this becomes a problem, it can be fixed by moving oldConnectionsCounter back into m_connectionsCounter, after clear()ing it. Sister change to 485727b41ed777ee9392be8aa770adb1b4415aa6. Change-Id: I73f8a16356258b8af210a8b3e7b00c523ca169e4 Reviewed-by: Milian Wolff <milian.wolff@kdab.com>
Diffstat (limited to 'src/webchannel/signalhandler_p.h')
-rw-r--r--src/webchannel/signalhandler_p.h8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/webchannel/signalhandler_p.h b/src/webchannel/signalhandler_p.h
index 57b9ff3..fd251b1 100644
--- a/src/webchannel/signalhandler_p.h
+++ b/src/webchannel/signalhandler_p.h
@@ -249,12 +249,12 @@ int SignalHandler<Receiver>::qt_metacall(QMetaObject::Call call, int methodId, v
template<class Receiver>
void SignalHandler<Receiver>::clear()
{
- foreach (const SignalConnectionHash &connections, m_connectionsCounter) {
- foreach (const ConnectionPair &connection, connections) {
+ // "consume loop": disconnectNotify() calls unknown code
+ const auto oldConnectionsCounter = std::exchange(m_connectionsCounter, {});
+ for (const SignalConnectionHash &connections : oldConnectionsCounter) {
+ for (const ConnectionPair &connection : connections)
QObject::disconnect(connection.first);
- }
}
- m_connectionsCounter.clear();
const SignalArgumentHash keep = m_signalArgumentTypes.take(&QObject::staticMetaObject);
m_signalArgumentTypes.clear();
m_signalArgumentTypes[&QObject::staticMetaObject] = keep;