From 48b38fb2b042fba5a0e1aed4f6d4fa6f29a51af0 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Wed, 23 May 2012 19:54:49 +0200 Subject: [PATCH] Simple optimisation for the construction of a QSharedPointer Let the constructor initialise the "value" member. In the case of create(), which already initialised "value", simply merge the two functions for more readability. Change-Id: I5638b3d42af3d0f5988f815e0f91d591fa1897a8 Reviewed-by: Lars Knoll --- src/corelib/tools/qsharedpointer_impl.h | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/corelib/tools/qsharedpointer_impl.h b/src/corelib/tools/qsharedpointer_impl.h index db4a0587d2..d22ceb2d69 100644 --- a/src/corelib/tools/qsharedpointer_impl.h +++ b/src/corelib/tools/qsharedpointer_impl.h @@ -294,7 +294,7 @@ public: QSharedPointer() : value(0), d(0) { } ~QSharedPointer() { deref(); } - inline explicit QSharedPointer(T *ptr) // throws + inline explicit QSharedPointer(T *ptr) : value(ptr) // noexcept { internalConstruct(ptr, &QtSharedPointer::normalDeleter); } template @@ -380,7 +380,7 @@ public: static inline QSharedPointer create() { QSharedPointer result(Qt::Uninitialized); - result.internalCreate(); + result.d = QtSharedPointer::ExternalRefCountWithContiguousData::create(&result.value); // now initialize the data new (result.data()) T(); @@ -413,15 +413,9 @@ private: internalFinishConstruction(ptr); } - inline void internalCreate() - { - d = QtSharedPointer::ExternalRefCountWithContiguousData::create(&value); - } - inline void internalFinishConstruction(T *ptr) { - value = ptr; - if (ptr) d->setQObjectShared(ptr, true); + d->setQObjectShared(ptr, true); #ifdef QT_SHAREDPOINTER_TRACK_POINTERS if (ptr) internalSafetyCheckAdd(d, ptr); #endif