From: Kent Hansen Date: Sun, 3 Jun 2012 18:30:49 +0000 (+0200) Subject: Avoid string-based lookup in IS_SIGNAL_CONNECTED X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=6f7bb92e5df069716bef9639c965b4c8a9aaaabf;p=konrad%2Fqtdeclarative.git Avoid string-based lookup in IS_SIGNAL_CONNECTED 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 --- diff --git a/src/particles/qquickcustomaffector.cpp b/src/particles/qquickcustomaffector.cpp index 72b1536..819dd12 100644 --- a/src/particles/qquickcustomaffector.cpp +++ b/src/particles/qquickcustomaffector.cpp @@ -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) diff --git a/src/particles/qquickparticleaffector.cpp b/src/particles/qquickparticleaffector.cpp index 978c53e..61396b1 100644 --- a/src/particles/qquickparticleaffector.cpp +++ b/src/particles/qquickparticleaffector.cpp @@ -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)); } diff --git a/src/particles/qquickparticleemitter.cpp b/src/particles/qquickparticleemitter.cpp index eb965a7..6e53b09 100644 --- a/src/particles/qquickparticleemitter.cpp +++ b/src/particles/qquickparticleemitter.cpp @@ -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() diff --git a/src/particles/qquicktrailemitter.cpp b/src/particles/qquicktrailemitter.cpp index e9d8611..68b43a0 100644 --- a/src/particles/qquicktrailemitter.cpp +++ b/src/particles/qquicktrailemitter.cpp @@ -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(){ diff --git a/src/qml/qml/qqmlglobal_p.h b/src/qml/qml/qqmlglobal_p.h index 3ed7286..75974a4 100644 --- a/src/qml/qml/qqmlglobal_p.h +++ b/src/qml/qml/qqmlglobal_p.h @@ -45,6 +45,7 @@ #include #include #include +#include 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) diff --git a/src/quick/items/context2d/qquickcanvasitem.cpp b/src/quick/items/context2d/qquickcanvasitem.cpp index 88f0fd1..24d71ac 100644 --- a/src/quick/items/context2d/qquickcanvasitem.cpp +++ b/src/quick/items/context2d/qquickcanvasitem.cpp @@ -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 diff --git a/src/quick/items/qquickmousearea.cpp b/src/quick/items/qquickmousearea.cpp index e561976..c1d1c9d 100644 --- a/src/quick/items/qquickmousearea.cpp +++ b/src/quick/items/qquickmousearea.cpp @@ -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) diff --git a/src/quick/items/qquicktext.cpp b/src/quick/items/qquicktext.cpp index 1f16cbd..4ab5649 100644 --- a/src/quick/items/qquicktext.cpp +++ b/src/quick/items/qquicktext.cpp @@ -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 */ diff --git a/src/quick/items/qquickvisualdatamodel.cpp b/src/quick/items/qquickvisualdatamodel.cpp index fe0dd00..6f5934e 100644 --- a/src/quick/items/qquickvisualdatamodel.cpp +++ b/src/quick/items/qquickvisualdatamodel.cpp @@ -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 removed = engineData(engine)->array(engine, changeSet.removes()); diff --git a/src/quick/items/qquickvisualdatamodel_p_p.h b/src/quick/items/qquickvisualdatamodel_p_p.h index 9a6c8c3..b88c8a4 100644 --- a/src/quick/items/qquickvisualdatamodel_p_p.h +++ b/src/quick/items/qquickvisualdatamodel_p_p.h @@ -210,6 +210,7 @@ public: return static_cast(QObjectPrivate::get(group)); } void setModel(QQuickVisualDataModel *model, Compositor::Group group); + bool isChangedConnected(); void emitChanges(QV8Engine *engine); void emitModelUpdated(bool reset);