From d359b0af2b93aeb9c22714be1cec881417650ed8 Mon Sep 17 00:00:00 2001 From: Kent Hansen Date: Mon, 25 Jun 2012 20:19:11 +0200 Subject: Call QObject::disconnectNotify() when receiver is destroyed Store the signal index in QObjectPrivate::Connection, thereby making it available in "implicit" disconnect contexts (i.e., receiver deletion). This change does not cause the size of QObjectPrivate::Connection to grow (still 40 bytes on 32-bit Linux, 72 bytes on 64-bit Mac). Valgrinding the new benchmark indicates that the percentage of the time spent in the QObject destructor increased from 7.8% to 8.4% on ia32, for that particular stress test; the increase is the combined cost of calling metaObject(), QMetaObjectPrivate::signal(), and disconnectNotify() for one connection. In practice, the measured wallclock time increased by about 3ms for a 500ms run (which repeatedly constructs, connects, and destroys an object). Task-number: QTBUG-4844 Change-Id: I1beb01c753f31542fc0acb62edb4c6d165fcc5b4 Reviewed-by: Olivier Goffart Reviewed-by: Bradley T. Hughes --- tests/auto/corelib/kernel/qobject/tst_qobject.cpp | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'tests/auto/corelib/kernel/qobject/tst_qobject.cpp') diff --git a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp index 0cdce500fa..479cdd3ca8 100644 --- a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp +++ b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp @@ -978,8 +978,26 @@ void tst_QObject::disconnectNotify_receiverDestroyed() QVERIFY(QObject::connect((SenderObject*)s, SIGNAL(signal1()), (ReceiverObject*)r, SLOT(slot1()))); delete r; - // disconnectNotify() is not called, but it probably should be. - QVERIFY(s->disconnectedSignals.isEmpty()); + QCOMPARE(s->disconnectedSignals.count(), 1); + QCOMPARE(s->disconnectedSignals.at(0), QMetaMethod::fromSignal(&SenderObject::signal1)); + + s->disconnectedSignals.clear(); + r = new NotifyObject; + + QVERIFY(QObject::connect((SenderObject*)s, SIGNAL(signal3()), (ReceiverObject*)r, SLOT(slot3()))); + + delete r; + QCOMPARE(s->disconnectedSignals.count(), 1); + QCOMPARE(s->disconnectedSignals.at(0), QMetaMethod::fromSignal(&SenderObject::signal3)); + + s->disconnectedSignals.clear(); + r = new NotifyObject; + + QVERIFY(QObject::connect((SenderObject*)s, SIGNAL(destroyed()), (ReceiverObject*)r, SLOT(slot3()))); + + delete r; + QCOMPARE(s->disconnectedSignals.count(), 1); + QCOMPARE(s->disconnectedSignals.at(0), QMetaMethod::fromSignal(&QObject::destroyed)); delete s; } -- cgit v1.2.3