diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2012-05-23 20:26:58 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2012-10-10 08:45:22 +0200 |
commit | 267b1a791d9527fed34c44c53440298331224542 (patch) | |
tree | 93e7070bde7ea65dbdedafcb6e3c1074cfe89871 /src/corelib/tools/qsharedpointer.cpp | |
parent | 1c8739eda12b79943fd587e9e724f734938244c7 (diff) |
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<T> 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 <ogoffart@woboq.com>
Diffstat (limited to 'src/corelib/tools/qsharedpointer.cpp')
-rw-r--r-- | src/corelib/tools/qsharedpointer.cpp | 7 |
1 files changed, 7 insertions, 0 deletions
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 |