[Qt] Simplify storage and reduce size of QtConnectionObject
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 13 Aug 2012 20:33:18 +0000 (20:33 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 13 Aug 2012 20:33:18 +0000 (20:33 +0000)
https://bugs.webkit.org/show_bug.cgi?id=93868

Patch by Simon Hausmann <simon.hausmann@nokia.com> on 2012-08-13
Reviewed by Kenneth Rohde Christiansen.

The connection object is a child of the sender QObject, so we can use parent()
whenever we need the sender instead of keeping an extra QObject pointer. Also
QtConnectionObject kept a RefPtr to the Instance, but actually only needed the
root object, so we can store a pointer to that instead.

* bridge/qt/qt_runtime.cpp:
(JSC::Bindings::QtConnectionObject::QtConnectionObject):
(JSC::Bindings::QtConnectionObject::~QtConnectionObject):
(JSC::Bindings::QtConnectionObject::execute):
(JSC::Bindings::QtConnectionObject::match):
* bridge/qt/qt_runtime.h:
(QtConnectionObject):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@125442 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/bridge/qt/qt_runtime.cpp
Source/WebCore/bridge/qt/qt_runtime.h

index 473b424..edc8235 100644 (file)
@@ -1,3 +1,23 @@
+2012-08-13  Simon Hausmann  <simon.hausmann@nokia.com>
+
+        [Qt] Simplify storage and reduce size of QtConnectionObject
+        https://bugs.webkit.org/show_bug.cgi?id=93868
+
+        Reviewed by Kenneth Rohde Christiansen.
+
+        The connection object is a child of the sender QObject, so we can use parent()
+        whenever we need the sender instead of keeping an extra QObject pointer. Also
+        QtConnectionObject kept a RefPtr to the Instance, but actually only needed the
+        root object, so we can store a pointer to that instead.
+
+        * bridge/qt/qt_runtime.cpp:
+        (JSC::Bindings::QtConnectionObject::QtConnectionObject):
+        (JSC::Bindings::QtConnectionObject::~QtConnectionObject):
+        (JSC::Bindings::QtConnectionObject::execute):
+        (JSC::Bindings::QtConnectionObject::match):
+        * bridge/qt/qt_runtime.h:
+        (QtConnectionObject):
+
 2012-08-13  Zan Dobersek  <zandobersek@gmail.com>
 
         Media(Stream|Element)AudioSourceNode should be guarded by the WEB_AUDIO condition as well
index 211e4f9..2cd2f58 100644 (file)
@@ -1525,8 +1525,7 @@ QMultiMap<QObject*, QtConnectionObject*> QtConnectionObject::connections;
 QtConnectionObject::QtConnectionObject(JSContextRef context, PassRefPtr<QtInstance> senderInstance, int signalIndex, JSObjectRef receiver, JSObjectRef receiverFunction)
     : QObject(senderInstance->getObject())
     , m_context(JSContextGetGlobalContext(context))
-    , m_senderInstance(senderInstance)
-    , m_originalSender(m_senderInstance->getObject())
+    , m_rootObject(senderInstance->rootObject())
     , m_signalIndex(signalIndex)
     , m_receiver(receiver)
     , m_receiverFunction(receiverFunction)
@@ -1538,9 +1537,7 @@ QtConnectionObject::QtConnectionObject(JSContextRef context, PassRefPtr<QtInstan
 
 QtConnectionObject::~QtConnectionObject()
 {
-    // We can safely use m_originalSender because connection object will never outlive the sender,
-    // which is its QObject parent.
-    connections.remove(m_originalSender, this);
+    connections.remove(parent(), this);
 
     if (m_receiver)
         JSValueUnprotect(m_context, m_receiver);
@@ -1636,14 +1633,7 @@ int QtConnectionObject::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
 
 void QtConnectionObject::execute(void** argv)
 {
-    QObject* sender = m_senderInstance->getObject();
-    if (!sender) {
-        qWarning() << "sender deleted, cannot deliver signal";
-        return;
-    }
-
-    ASSERT(sender == m_originalSender);
-
+    QObject* sender = parent();
     const QMetaObject* meta = sender->metaObject();
     const QMetaMethod method = meta->method(m_signalIndex);
 
@@ -1655,11 +1645,10 @@ void QtConnectionObject::execute(void** argv)
 
     // TODO: remove once conversion functions use JSC API.
     ExecState* exec = ::toJS(m_context);
-    RefPtr<RootObject> rootObject = m_senderInstance->rootObject();
 
     for (int i = 0; i < argc; i++) {
         int argType = method.parameterType(i);
-        args[i] = ::toRef(exec, convertQVariantToValue(exec, rootObject, QVariant(argType, argv[i+1])));
+        args[i] = ::toRef(exec, convertQVariantToValue(exec, m_rootObject, QVariant(argType, argv[i+1])));
     }
 
     JSObjectCallAsFunction(m_context, m_receiverFunction, m_receiver, argc, args.data(), 0);
@@ -1667,7 +1656,7 @@ void QtConnectionObject::execute(void** argv)
 
 bool QtConnectionObject::match(JSContextRef context, QObject* sender, int signalIndex, JSObjectRef receiver, JSObjectRef receiverFunction)
 {
-    if (sender != m_originalSender || signalIndex != m_signalIndex)
+    if (sender != parent() || signalIndex != m_signalIndex)
         return false;
     JSValueRef* ignoredException = 0;
     const bool receiverMatch = (!receiver && !m_receiver) || (receiver && m_receiver && JSValueIsEqual(context, receiver, m_receiver, ignoredException));
index 141ef25..98756d1 100644 (file)
@@ -141,10 +141,7 @@ public:
 
 private:
     JSGlobalContextRef m_context;
-    RefPtr<QtInstance> m_senderInstance;
-
-    // We use this as key in active connections multimap.
-    QObject* m_originalSender;
+    RefPtr<RootObject> m_rootObject;
 
     int m_signalIndex;
     JSObjectRef m_receiver;