summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qbytearray.cpp
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2012-06-05 17:21:19 +0200
committerThiago Macieira <thiago.macieira@intel.com>2016-09-07 14:35:51 +0000
commit42f974f56b18e365c3343545a9491452683fed30 (patch)
tree8325af7fad8f19acad3ee34ea12e0591ded32162 /src/corelib/tools/qbytearray.cpp
parent8e5cd8017e9a88de426b3c23c328a68a70089b1c (diff)
Add QArrayData::reallocateUnaligned for QString and QByteArray
This function reallocates a QArrayData block with realloc() but, as the name says, it's only valid for types that do not increase the alignment requirements. I don't think it's worth doing this for types that do increase the alignment requirements, since we don't know the alignment of the pointer returned by realloc(). If the new pointer modulo the alignment is different from the old pointer modulo the alignment, we'd have to memmove data around, which would be quite inefficient (realloc might have memcpy'ed already and this memmove would copy data to nearby). This function is intended to be used especially in QString and QByteArray, which were already using realloc() on pointers created by QArrayData::allocate. Change-Id: I45b61247db2e84797ad794c1049c47a09c1fb29a Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
Diffstat (limited to 'src/corelib/tools/qbytearray.cpp')
-rw-r--r--src/corelib/tools/qbytearray.cpp13
1 files changed, 1 insertions, 12 deletions
diff --git a/src/corelib/tools/qbytearray.cpp b/src/corelib/tools/qbytearray.cpp
index 266c2e9b57..5b5fbaa94b 100644
--- a/src/corelib/tools/qbytearray.cpp
+++ b/src/corelib/tools/qbytearray.cpp
@@ -1706,19 +1706,8 @@ void QByteArray::reallocData(uint alloc, Data::AllocationOptions options)
Data::deallocate(d);
d = x;
} else {
- size_t blockSize;
- if (options & Data::Grow) {
- auto r = qCalculateGrowingBlockSize(alloc, sizeof(QChar), sizeof(Data));
- blockSize = r.size;
- alloc = uint(r.elementCount);
- } else {
- blockSize = qCalculateBlockSize(alloc, sizeof(QChar), sizeof(Data));
- }
-
- Data *x = static_cast<Data *>(::realloc(d, blockSize));
+ Data *x = Data::reallocateUnaligned(d, alloc, options);
Q_CHECK_PTR(x);
- x->alloc = alloc;
- x->capacityReserved = (options & Data::CapacityReserved) ? 1 : 0;
d = x;
}
}