From 110890e091cd1f112b18196048f62efe7b858e19 Mon Sep 17 00:00:00 2001 From: Milian Wolff Date: Thu, 19 Dec 2013 17:21:32 +0100 Subject: Cleanup and optimize code a bit by calling senderSignalIndex less. Profiling shows that sender() and senderSignalIndex(), which again calls sender() internally, are the hotspots in benchPropertyUpdates. To speed things up a bit, call senderSignalIndex only once whenever a signal is emitted. The performance gain is about 27% (16ms vs. 22ms). While at it, also re-use the global s_destroyedSignalIndex static and also call sender() only once even when assertions are enabled. Change-Id: I90cd1a2b453e5c40d0f41276968f4545b42076bc Reviewed-by: Zeno Albisser --- src/webchannel/signalhandler_p.h | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'src/webchannel/signalhandler_p.h') diff --git a/src/webchannel/signalhandler_p.h b/src/webchannel/signalhandler_p.h index 5bc1f4d..7360028 100644 --- a/src/webchannel/signalhandler_p.h +++ b/src/webchannel/signalhandler_p.h @@ -245,12 +245,16 @@ int SignalHandler::qt_metacall(QMetaObject::Call call, int methodId, v if (call == QMetaObject::InvokeMetaMethod) { if (methodId == 0) { - Q_ASSERT(sender()); - Q_ASSERT(senderSignalIndex() != -1); - dispatch(sender(), senderSignalIndex(), args); - static const int destroyedIndex = metaObject()->indexOfSignal("destroyed(QObject*)"); - if (senderSignalIndex() == destroyedIndex) { - ConnectionHash::iterator it = m_connectionsCounter.find(sender()); + const QObject *object = sender(); + Q_ASSERT(object); + const int signalIndex = senderSignalIndex(); + Q_ASSERT(signalIndex != -1); + + dispatch(object, signalIndex, args); + + if (signalIndex == s_destroyedSignalIndex) { + // disconnect on QObject::destroyed + ConnectionHash::iterator it = m_connectionsCounter.find(object); Q_ASSERT(it != m_connectionsCounter.end()); foreach (const ConnectionPair &connection, *it) { QObject::disconnect(connection.first); -- cgit v1.2.3