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 <lars.knoll@nokia.com>
This commit is contained in:
Thiago Macieira 2012-05-23 19:54:49 +02:00 committed by Qt by Nokia
parent 6daea46918
commit 48b38fb2b0

View File

@ -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<T>); }
template <typename Deleter>
@ -380,7 +380,7 @@ public:
static inline QSharedPointer<T> create()
{
QSharedPointer<T> result(Qt::Uninitialized);
result.internalCreate();
result.d = QtSharedPointer::ExternalRefCountWithContiguousData<T>::create(&result.value);
// now initialize the data
new (result.data()) T();
@ -413,15 +413,9 @@ private:
internalFinishConstruction(ptr);
}
inline void internalCreate()
{
d = QtSharedPointer::ExternalRefCountWithContiguousData<T>::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