Avoid string-based lookup in IS_SIGNAL_CONNECTED
authorKent Hansen <kent.hansen@nokia.com>
Sun, 3 Jun 2012 18:30:49 +0000 (20:30 +0200)
committerQt by Nokia <qt-info@nokia.com>
Sun, 10 Jun 2012 11:47:15 +0000 (13:47 +0200)
Specify the signal as a member function suitable for passing to
QMetaMethod::fromSignal(), and use the new function
QMetaObjectPrivate::signalIndex(QMetaMethod) to get the index in the
signal range.

Change-Id: If16daa24c2699f7749a17decb611cf395d89d0c4
Reviewed-by: Aaron Kennedy <aaron.kennedy@nokia.com>
src/particles/qquickcustomaffector.cpp
src/particles/qquickparticleaffector.cpp
src/particles/qquickparticleemitter.cpp
src/particles/qquicktrailemitter.cpp
src/qml/qml/qqmlglobal_p.h
src/quick/items/context2d/qquickcanvasitem.cpp
src/quick/items/qquickmousearea.cpp
src/quick/items/qquicktext.cpp
src/quick/items/qquickvisualdatamodel.cpp
src/quick/items/qquickvisualdatamodel_p_p.h

index 72b1536..819dd12 100644 (file)
@@ -103,7 +103,7 @@ QQuickCustomAffector::QQuickCustomAffector(QQuickItem *parent) :
 
 bool QQuickCustomAffector::isAffectConnected()
 {
-    IS_SIGNAL_CONNECTED(this, "affectParticles(QQmlV8Handle,qreal)");
+    IS_SIGNAL_CONNECTED(this, QQuickCustomAffector, affectParticles, (QQmlV8Handle,qreal));
 }
 
 void QQuickCustomAffector::affectSystem(qreal dt)
index 978c53e..61396b1 100644 (file)
@@ -135,7 +135,7 @@ QQuickParticleAffector::QQuickParticleAffector(QQuickItem *parent) :
 
 bool QQuickParticleAffector::isAffectedConnected()
 {
-    IS_SIGNAL_CONNECTED(this, "affected(qreal,qreal)");
+    IS_SIGNAL_CONNECTED(this, QQuickParticleAffector, affected, (qreal,qreal));
 }
 
 
index eb965a7..6e53b09 100644 (file)
@@ -255,7 +255,7 @@ QQuickParticleEmitter::~QQuickParticleEmitter()
 
 bool QQuickParticleEmitter::isEmitConnected()
 {
-    IS_SIGNAL_CONNECTED(this, "emitParticles(QQmlV8Handle)");
+    IS_SIGNAL_CONNECTED(this, QQuickParticleEmitter, emitParticles, (QQmlV8Handle));
 }
 
 void QQuickParticleEmitter::componentComplete()
index e9d8611..68b43a0 100644 (file)
@@ -128,7 +128,7 @@ QQuickTrailEmitter::QQuickTrailEmitter(QQuickItem *parent) :
 
 bool QQuickTrailEmitter::isEmitFollowConnected()
 {
-    IS_SIGNAL_CONNECTED(this, "emitFollowParticles(QQmlV8Handle,QQmlV8Handle)");
+    IS_SIGNAL_CONNECTED(this, QQuickTrailEmitter, emitFollowParticles, (QQmlV8Handle,QQmlV8Handle));
 }
 
 void QQuickTrailEmitter::recalcParticlesPerSecond(){
index 3ed7286..75974a4 100644 (file)
@@ -45,6 +45,7 @@
 #include <private/qtqmlglobal_p.h>
 #include <QtCore/QObject>
 #include <private/qqmlpropertycache_p.h>
+#include <private/qmetaobject_p.h>
 
 QT_BEGIN_HEADER
 
@@ -165,16 +166,13 @@ T qmlobject_cast(QObject *object)
 
 bool Q_QML_PRIVATE_EXPORT QQml_isSignalConnected(QObject*, int, int);
 
-#define IS_SIGNAL_CONNECTED(Sender, Signal) \
+#define IS_SIGNAL_CONNECTED(Sender, SenderType, Name, Arguments) \
 do { \
     QObject *sender = (Sender); \
-    const char *signal = (Signal); \
-    static int signalIdx = -1; \
-    static int methodIdx = -1; \
-    if (signalIdx < 0) { \
-        signalIdx = QObjectPrivate::get(sender)->signalIndex(signal); \
-        methodIdx = sender->metaObject()->indexOfSignal(signal); \
-    } \
+    void (SenderType::*signal)Arguments = &SenderType::Name; \
+    static QMetaMethod method = QMetaMethod::fromSignal(signal); \
+    static int signalIdx = QMetaObjectPrivate::signalIndex(method); \
+    static int methodIdx = method.methodIndex(); \
     return QQml_isSignalConnected(sender, signalIdx, methodIdx); \
 } while (0)
 
index 88f0fd1..24d71ac 100644 (file)
@@ -556,7 +556,7 @@ QQuickCanvasContext* QQuickCanvasItem::rawContext() const
 
 bool QQuickCanvasItem::isPaintConnected()
 {
-    IS_SIGNAL_CONNECTED(this, "paint(QRect)");
+    IS_SIGNAL_CONNECTED(this, QQuickCanvasItem, paint, (const QRect &));
 }
 
 void QQuickCanvasItem::sceneGraphInitialized()
@@ -1074,4 +1074,4 @@ QRect QQuickCanvasItem::tiledRect(const QRectF &window, const QSize &tileSize)
     the Canvas has been rendered.
 */
 
-QT_END_NAMESPACE
\ No newline at end of file
+QT_END_NAMESPACE
index e561976..c1d1c9d 100644 (file)
@@ -220,25 +220,25 @@ void QQuickMouseAreaPrivate::saveEvent(QMouseEvent *event)
 bool QQuickMouseAreaPrivate::isPressAndHoldConnected()
 {
     Q_Q(QQuickMouseArea);
-    IS_SIGNAL_CONNECTED(q, "pressAndHold(QQuickMouseEvent*)");
+    IS_SIGNAL_CONNECTED(q, QQuickMouseArea, pressAndHold, (QQuickMouseEvent *));
 }
 
 bool QQuickMouseAreaPrivate::isDoubleClickConnected()
 {
     Q_Q(QQuickMouseArea);
-    IS_SIGNAL_CONNECTED(q, "doubleClicked(QQuickMouseEvent*)");
+    IS_SIGNAL_CONNECTED(q, QQuickMouseArea, doubleClicked, (QQuickMouseEvent *));
 }
 
 bool QQuickMouseAreaPrivate::isClickConnected()
 {
     Q_Q(QQuickMouseArea);
-    IS_SIGNAL_CONNECTED(q, "clicked(QQuickMouseEvent*)");
+    IS_SIGNAL_CONNECTED(q, QQuickMouseArea, clicked, (QQuickMouseEvent *));
 }
 
 bool QQuickMouseAreaPrivate::isWheelConnected()
 {
     Q_Q(QQuickMouseArea);
-    IS_SIGNAL_CONNECTED(q, "wheel(QQuickWheelEvent*)");
+    IS_SIGNAL_CONNECTED(q, QQuickMouseArea, wheel, (QQuickWheelEvent *));
 }
 
 void QQuickMouseAreaPrivate::propagate(QQuickMouseEvent* event, PropagateType t)
index 1f16cbd..4ab5649 100644 (file)
@@ -595,7 +595,7 @@ void QQuickText::doLayout()
 bool QQuickTextPrivate::isLineLaidOutConnected()
 {
     Q_Q(QQuickText);
-    IS_SIGNAL_CONNECTED(q, "lineLaidOut(QQuickTextLine*)");
+    IS_SIGNAL_CONNECTED(q, QQuickText, lineLaidOut, (QQuickTextLine *));
 }
 
 void QQuickTextPrivate::setupCustomLineGeometry(QTextLine &line, qreal &height, int lineOffset)
@@ -2422,7 +2422,7 @@ QString QQuickTextPrivate::anchorAt(const QPointF &mousePos)
 bool QQuickTextPrivate::isLinkActivatedConnected()
 {
     Q_Q(QQuickText);
-    IS_SIGNAL_CONNECTED(q, "linkActivated(QString)");
+    IS_SIGNAL_CONNECTED(q, QQuickText, linkActivated, (const QString &));
 }
 
 /*!  \internal */
index fe0dd00..6f5934e 100644 (file)
@@ -2060,15 +2060,16 @@ void QQuickVisualDataGroupPrivate::setModel(QQuickVisualDataModel *m, Compositor
     group = g;
 }
 
-static bool isChangedConnected(QObject *obj)
+bool QQuickVisualDataGroupPrivate::isChangedConnected()
 {
-    IS_SIGNAL_CONNECTED(obj, "changed(QQmlV8Handle,QQmlV8Handle)");
+    Q_Q(QQuickVisualDataGroup);
+    IS_SIGNAL_CONNECTED(q, QQuickVisualDataGroup, changed, (const QQmlV8Handle &,const QQmlV8Handle &));
 }
 
 void QQuickVisualDataGroupPrivate::emitChanges(QV8Engine *engine)
 {
     Q_Q(QQuickVisualDataGroup);
-    if (isChangedConnected(q) && !changeSet.isEmpty()) {
+    if (isChangedConnected() && !changeSet.isEmpty()) {
         v8::HandleScope handleScope;
         v8::Context::Scope contextScope(engine->context());
         v8::Local<v8::Object> removed  = engineData(engine)->array(engine, changeSet.removes());
index 9a6c8c3..b88c8a4 100644 (file)
@@ -210,6 +210,7 @@ public:
         return static_cast<QQuickVisualDataGroupPrivate *>(QObjectPrivate::get(group)); }
 
     void setModel(QQuickVisualDataModel *model, Compositor::Group group);
+    bool isChangedConnected();
     void emitChanges(QV8Engine *engine);
     void emitModelUpdated(bool reset);