From 267b1a791d9527fed34c44c53440298331224542 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Wed, 23 May 2012 20:26:58 +0200 Subject: Optimise the deletion of a QSharedPointer with no custom deleter When QSharedPointer is created with no user-specified custom deleter, instead of storing a pointer in ExternalRefCount::destroyer to a static function which, in turn, calls normalDeleter indirectly (via another function pointer), specialise the CustomDeleter class and make it not store the pointer, but instead do the deleting directly. The benefits are: - the QSharedPointer's private data is smaller - there is no double-indirection via indirect jumps to the actual deleter Change-Id: Ice5653c144912efb1226e432267a047b9799aaca Reviewed-by: Olivier Goffart --- src/corelib/tools/qsharedpointer.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/corelib/tools/qsharedpointer.cpp') diff --git a/src/corelib/tools/qsharedpointer.cpp b/src/corelib/tools/qsharedpointer.cpp index 7dc1caf57a..167771027e 100644 --- a/src/corelib/tools/qsharedpointer.cpp +++ b/src/corelib/tools/qsharedpointer.cpp @@ -230,6 +230,13 @@ structure will be 12+8+4 = 24 bytes on 32-bit architectures, 16+16+8 = 40 bytes on 64-bit ones. + If the deleter was not specified when creating the QSharedPointer object + (i.e., if a standard \tt delete call is expected), then there's an + optimization that avoids the need to store another function pointer in + ExternalRefCountWithCustomDeleter. Instead, a template specialization makes + a direct delete call. The size of the structure, in this case, is 12+4 = 16 + bytes on 32-bit architectures, 16+8 = 24 bytes on 64-bit ones. + \section3 QtSharedPointer::ExternalRefCountWithContiguousData This class also derives from ExternalRefCountData and it is -- cgit v1.2.3