diff options
author | Lars Knoll <lars.knoll@qt.io> | 2020-10-30 13:42:09 +0100 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2020-11-04 11:21:37 +0100 |
commit | 32a703e2779e697a9a7d75f6cbc6e555187d7fca (patch) | |
tree | ea9d56952efd13d36ae455771ace6fa144bbe568 /src | |
parent | 50ec3252ac5d61a13fab01801ef42729d6f3a7c6 (diff) |
Don't move data in QArrayDataOps::reallocate()
reallocate() should only ever call realloc(), and only be used to
create more space at the end of the data.
Change-Id: I2ac4dbc90d2afaa571bb620108d7984356712cb2
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/text/qbytearray.cpp | 6 | ||||
-rw-r--r-- | src/corelib/text/qstring.cpp | 4 | ||||
-rw-r--r-- | src/corelib/tools/qarraydataops.h | 16 |
3 files changed, 7 insertions, 19 deletions
diff --git a/src/corelib/text/qbytearray.cpp b/src/corelib/text/qbytearray.cpp index 18ee2dbfb3..945a2a26fd 100644 --- a/src/corelib/text/qbytearray.cpp +++ b/src/corelib/text/qbytearray.cpp @@ -671,7 +671,7 @@ QByteArray qUncompress(const uchar* data, qsizetype nbytes) return invalidCompressedData(); } else { // grow the block - d->reallocate(d->allocatedCapacity()*2, QByteArray::Data::GrowsForward); + d->reallocate(d->allocatedCapacity()*2); if (Q_UNLIKELY(d.data() == nullptr)) return invalidCompressedData(); } @@ -1719,7 +1719,7 @@ void QByteArray::reallocData(qsizetype alloc, Data::ArrayOptions options) dd.data()[dd.size] = 0; d = dd; } else { - d->reallocate(alloc, options); + d->reallocate(alloc); } } @@ -1734,7 +1734,7 @@ void QByteArray::reallocGrowData(qsizetype n) dd.data()[dd.size] = 0; d = dd; } else { - d->reallocate(d.constAllocatedCapacity() + n, Data::GrowsForward); + d->reallocate(d.constAllocatedCapacity() + n); } } diff --git a/src/corelib/text/qstring.cpp b/src/corelib/text/qstring.cpp index 51af7fe32a..3e6188a38d 100644 --- a/src/corelib/text/qstring.cpp +++ b/src/corelib/text/qstring.cpp @@ -2516,7 +2516,7 @@ void QString::reallocData(qsizetype alloc, Data::ArrayOptions allocOptions) dd.data()[dd.size] = 0; d = dd; } else { - d->reallocate(alloc, allocOptions); + d->reallocate(alloc); } } @@ -2531,7 +2531,7 @@ void QString::reallocGrowData(qsizetype n) dd.data()[dd.size] = 0; d = dd; } else { - d->reallocate(d.constAllocatedCapacity() + n, Data::GrowsForward); + d->reallocate(d.constAllocatedCapacity() + n); } } diff --git a/src/corelib/tools/qarraydataops.h b/src/corelib/tools/qarraydataops.h index 3aab72f8ae..140d79b2e3 100644 --- a/src/corelib/tools/qarraydataops.h +++ b/src/corelib/tools/qarraydataops.h @@ -457,21 +457,9 @@ public: } } - void reallocate(qsizetype alloc, typename Data::ArrayOptions options) + void reallocate(qsizetype alloc) { - // when reallocating, take care of the situation when no growth is - // happening - need to move the data in this case, unfortunately - const bool grows = options & (Data::GrowsForward | Data::GrowsBackwards); - - // ### optimize me: there may be cases when moving is not obligatory - if (const auto gap = this->freeSpaceAtBegin(); this->d && !grows && gap) { - auto oldBegin = this->begin(); - this->ptr -= gap; - ::memmove(static_cast<void *>(this->begin()), static_cast<void *>(oldBegin), - this->size * sizeof(T)); - } - - auto pair = Data::reallocateUnaligned(this->d, this->ptr, alloc, options); + auto pair = Data::reallocateUnaligned(this->d, this->ptr, alloc, QArrayData::GrowsBackwards); this->d = pair.first; this->ptr = pair.second; } |