summaryrefslogtreecommitdiffstats
path: root/src/corelib
diff options
context:
space:
mode:
authorOlivier Goffart <olivier.goffart@nokia.com>2010-04-20 16:17:38 (GMT)
committerOlivier Goffart <olivier.goffart@nokia.com>2010-04-21 09:11:10 (GMT)
commit48b2025663c93003cd00b807bb74d220c933b78b (patch)
treea79aac6a78db517a43a7ea454f06c00cf516f380 /src/corelib
parenta087cfe4049292b726a5fea34f552ad86b44c2ae (diff)
downloadQt-48b2025663c93003cd00b807bb74d220c933b78b.zip
Qt-48b2025663c93003cd00b807bb74d220c933b78b.tar.gz
Qt-48b2025663c93003cd00b807bb74d220c933b78b.tar.bz2
Optimize ~QObject
By avoiding to lock mutextes when not needed. According to experiment, many object are destroyed without any connection attached to them. (80% with qml, 50% with creator) d->currentSender does not need to be protected by the mutex since we are in the destructor. We do not need Q_TRY since the mutex is grenteed to exist if there is connections. We do not need to call QCoreApplication::removePostedEvents if there is not events to process. And d->postedEvents can be checked outside of the lock since it cannot be incremented anymore in the destructor Reviewed-by: Roberto Raggi Reviewed-by: Brad
Diffstat (limited to 'src/corelib')
-rw-r--r--src/corelib/kernel/qobject.cpp26
1 files changed, 11 insertions, 15 deletions
diff --git a/src/corelib/kernel/qobject.cpp b/src/corelib/kernel/qobject.cpp
index 3a37cb1..6a6db51 100644
--- a/src/corelib/kernel/qobject.cpp
+++ b/src/corelib/kernel/qobject.cpp
@@ -859,19 +859,14 @@ QObject::~QObject()
if (d->declarativeData)
QAbstractDeclarativeData::destroyed(d->declarativeData, this);
- {
- QMutex *signalSlotMutex = 0;
- QT_TRY {
- signalSlotMutex = signalSlotLock(this);
- } QT_CATCH(const std::bad_alloc &) {
- // out of memory - swallow to prevent a crash
- }
- QMutexLocker locker(signalSlotMutex);
+ // set ref to zero to indicate that this object has been deleted
+ if (d->currentSender != 0)
+ d->currentSender->ref = 0;
+ d->currentSender = 0;
- // set ref to zero to indicate that this object has been deleted
- if (d->currentSender != 0)
- d->currentSender->ref = 0;
- d->currentSender = 0;
+ if (d->connectionLists || d->senders) {
+ QMutex *signalSlotMutex = signalSlotLock(this);
+ QMutexLocker locker(signalSlotMutex);
// disconnect all receivers
if (d->connectionLists) {
@@ -889,7 +884,7 @@ QObject::~QObject()
}
QMutex *m = signalSlotLock(c->receiver);
- bool needToUnlock = QOrderedMutexLocker::relock(locker.mutex(), m);
+ bool needToUnlock = QOrderedMutexLocker::relock(signalSlotMutex, m);
if (c->receiver) {
*c->prev = c->next;
@@ -917,7 +912,7 @@ QObject::~QObject()
QObject *sender = node->sender;
QMutex *m = signalSlotLock(sender);
node->prev = &node;
- bool needToUnlock = QOrderedMutexLocker::relock(locker.mutex(), m);
+ bool needToUnlock = QOrderedMutexLocker::relock(signalSlotMutex, m);
//the node has maybe been removed while the mutex was unlocked in relock?
if (!node || node->sender != sender) {
m->unlock();
@@ -951,7 +946,8 @@ QObject::~QObject()
qt_removeObject(this);
- QCoreApplication::removePostedEvents(this);
+ if (d->postedEvents)
+ QCoreApplication::removePostedEvents(this, 0);
if (d->parent) // remove it from parent object
d->setParent_helper(0);