Avoid string-based lookup of signals
authorKent Hansen <kent.hansen@nokia.com>
Wed, 30 May 2012 09:33:32 +0000 (11:33 +0200)
committerQt by Nokia <qt-info@nokia.com>
Fri, 1 Jun 2012 07:34:50 +0000 (09:34 +0200)
Change-Id: I5b83b5d07b6a5d2de86d0f37471cf59baa7b0e43
Reviewed-by: Michael Brasser <michael.brasser@nokia.com>
src/qml/qml/qqmlfile.cpp
src/quick/items/qquickrectangle.cpp
src/quick/items/qquickrectangle_p_p.h
src/quick/items/qquicktextcontrol.cpp
src/quick/util/qquickpixmapcache.cpp

index 9bdd2cd..b0da80f 100644 (file)
@@ -43,6 +43,7 @@
 
 #include <QtCore/qurl.h>
 #include <QtCore/qobject.h>
+#include <QtCore/qmetaobject.h>
 #include <private/qqmlengine_p.h>
 #include <private/qqmlglobal_p.h>
 
@@ -127,15 +128,14 @@ QQmlFileNetworkReply::QQmlFileNetworkReply(QQmlEngine *e, QQmlFilePrivate *p, co
 : m_engine(e), m_p(p), m_redirectCount(0), m_reply(0)
 {
     if (finishedIndex == -1) {
+        finishedIndex = QMetaMethod::fromSignal(&QQmlFileNetworkReply::finished).methodIndex();
+        downloadProgressIndex = QMetaMethod::fromSignal(&QQmlFileNetworkReply::downloadProgress).methodIndex();
         const QMetaObject *smo = &staticMetaObject;
-        finishedIndex = smo->indexOfSignal("finished()");
-        downloadProgressIndex = smo->indexOfSignal("downloadProgress(qint64,qint64)");
         networkFinishedIndex = smo->indexOfMethod("networkFinished()");
         networkDownloadProgressIndex = smo->indexOfMethod("networkDownloadProgress(qint64,qint64)");
 
-        const QMetaObject *rsmo = &QNetworkReply::staticMetaObject;
-        replyFinishedIndex = rsmo->indexOfSignal("finished()");
-        replyDownloadProgressIndex = rsmo->indexOfSignal("downloadProgress(qint64,qint64)");
+        replyFinishedIndex = QMetaMethod::fromSignal(&QNetworkReply::finished).methodIndex();
+        replyDownloadProgressIndex = QMetaMethod::fromSignal(&QNetworkReply::downloadProgress).methodIndex();
     }
     Q_ASSERT(finishedIndex != -1 && downloadProgressIndex != -1 &&
              networkFinishedIndex != -1 && networkDownloadProgressIndex != -1 &&
index f4fe471..b4156d9 100644 (file)
@@ -48,6 +48,7 @@
 #include <QtGui/qpixmapcache.h>
 #include <QtCore/qstringbuilder.h>
 #include <QtCore/qmath.h>
+#include <QtCore/qmetaobject.h>
 
 QT_BEGIN_NAMESPACE
 
@@ -414,7 +415,7 @@ void QQuickRectangle::setGradient(QQuickGradient *gradient)
         return;
     static int updatedSignalIdx = -1;
     if (updatedSignalIdx < 0)
-        updatedSignalIdx = QQuickGradient::staticMetaObject.indexOfSignal("updated()");
+        updatedSignalIdx = QMetaMethod::fromSignal(&QQuickGradient::updated).methodIndex();
     if (d->doUpdateSlotIdx < 0)
         d->doUpdateSlotIdx = QQuickRectangle::staticMetaObject.indexOfSlot("doUpdate()");
     if (d->gradient)
index cb923ee..934544b 100644 (file)
@@ -54,6 +54,7 @@
 //
 
 #include "qquickitem_p.h"
+#include <QtCore/qmetaobject.h>
 
 QT_BEGIN_NAMESPACE
 
@@ -88,7 +89,7 @@ public:
             pen = new QQuickPen;
             static int penChangedSignalIdx = -1;
             if (penChangedSignalIdx < 0)
-                penChangedSignalIdx = QQuickPen::staticMetaObject.indexOfSignal("penChanged()");
+                penChangedSignalIdx = QMetaMethod::fromSignal(&QQuickPen::penChanged).methodIndex();
             if (doUpdateSlotIdx < 0)
                 doUpdateSlotIdx = QQuickRectangle::staticMetaObject.indexOfSlot("doUpdate()");
             QMetaObject::connect(pen, penChangedSignalIdx, q, doUpdateSlotIdx);
index 751706d..b390679 100644 (file)
@@ -69,6 +69,7 @@
 #include <qvariant.h>
 #include <qurl.h>
 #include <qstylehints.h>
+#include <qmetaobject.h>
 
 // ### these should come from QStyleHints
 const int textCursorWidth = 1;
@@ -321,8 +322,8 @@ void QQuickTextControlPrivate::setContent(Qt::TextFormat format, const QString &
         doc->setUndoRedoEnabled(false);
 
     //Saving the index save some time.
-    static int contentsChangedIndex = QTextDocument::staticMetaObject.indexOfSignal("contentsChanged()");
-    static int textChangedIndex = QQuickTextControl::staticMetaObject.indexOfSignal("textChanged()");
+    static int contentsChangedIndex = QMetaMethod::fromSignal(&QTextDocument::contentsChanged).methodIndex();
+    static int textChangedIndex = QMetaMethod::fromSignal(&QQuickTextControl::textChanged).methodIndex();
     // avoid multiple textChanged() signals being emitted
     QMetaObject::disconnect(doc, contentsChangedIndex, q, textChangedIndex);
 
index 9f11062..3b9c59e 100644 (file)
@@ -66,6 +66,7 @@
 #include <private/qobject_p.h>
 #include <QSslError>
 #include <QQmlFile>
+#include <QMetaMethod>
 
 #define IMAGEREQUEST_MAX_REQUEST_COUNT       8
 #define IMAGEREQUEST_MAX_REDIRECT_RECURSION 16
@@ -633,12 +634,10 @@ void QQuickPixmapReader::cancel(QQuickPixmapReply *reply)
 void QQuickPixmapReader::run()
 {
     if (replyDownloadProgress == -1) {
-        const QMetaObject *nr = &QNetworkReply::staticMetaObject;
-        const QMetaObject *pr = &QQuickPixmapReply::staticMetaObject;
+        replyDownloadProgress = QMetaMethod::fromSignal(&QNetworkReply::downloadProgress).methodIndex();
+        replyFinished = QMetaMethod::fromSignal(&QNetworkReply::finished).methodIndex();
+        downloadProgress = QMetaMethod::fromSignal(&QQuickPixmapReply::downloadProgress).methodIndex();
         const QMetaObject *ir = &QQuickPixmapReaderThreadObject::staticMetaObject;
-        replyDownloadProgress = nr->indexOfSignal("downloadProgress(qint64,qint64)");
-        replyFinished = nr->indexOfSignal("finished()");
-        downloadProgress = pr->indexOfSignal("downloadProgress(qint64,qint64)");
         threadNetworkRequestDone = ir->indexOfSlot("networkRequestDone()");
     }
 
@@ -832,8 +831,8 @@ QQuickPixmapReply::QQuickPixmapReply(QQuickPixmapData *d)
 : data(d), engineForReader(0), requestSize(d->requestSize), url(d->url), loading(false), redirectCount(0)
 {
     if (finishedIndex == -1) {
-        finishedIndex = QQuickPixmapReply::staticMetaObject.indexOfSignal("finished()");
-        downloadProgressIndex = QQuickPixmapReply::staticMetaObject.indexOfSignal("downloadProgress(qint64,qint64)");
+        finishedIndex = QMetaMethod::fromSignal(&QQuickPixmapReply::finished).methodIndex();
+        downloadProgressIndex = QMetaMethod::fromSignal(&QQuickPixmapReply::downloadProgress).methodIndex();
     }
 }