summaryrefslogtreecommitdiffstats
path: root/src/corelib/text/qbytearray.cpp
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2020-10-30 14:21:34 +0100
committerLars Knoll <lars.knoll@qt.io>2020-11-04 11:21:46 +0100
commitb76fbb48fba51df95d1776b8c1ff358789d78031 (patch)
tree1955e13a6498318d8d485805af1558d995924829 /src/corelib/text/qbytearray.cpp
parent419eaa0679c3867d8d9a3da8845a3015e29800d7 (diff)
Clean up out allocation handling
Get rid of the allocation options inside the flags field of QArrayData, they are really a completely separate thing. Change-Id: I823750ab9e4ca85642a0bd0e471ee79c9cde43fb Reviewed-by: Andrei Golubev <andrei.golubev@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/text/qbytearray.cpp')
-rw-r--r--src/corelib/text/qbytearray.cpp21
1 files changed, 11 insertions, 10 deletions
diff --git a/src/corelib/text/qbytearray.cpp b/src/corelib/text/qbytearray.cpp
index 1a1b2d86b0..1b5fa8e5eb 100644
--- a/src/corelib/text/qbytearray.cpp
+++ b/src/corelib/text/qbytearray.cpp
@@ -1175,7 +1175,8 @@ QByteArray &QByteArray::operator=(const char *str)
const auto capacityAtEnd = d->allocatedCapacity() - d.freeSpaceAtBegin();
if (d->needsDetach() || len > capacityAtEnd
|| (len < size() && len < (capacityAtEnd >> 1)))
- reallocData(len, d->detachFlags());
+ // ### inefficient! reallocData() does copy the old data and we then overwrite it in the next line
+ reallocData(len, QArrayData::KeepSize);
memcpy(d.data(), str, len + 1); // include null terminator
d.size = len;
}
@@ -1676,7 +1677,7 @@ void QByteArray::resize(qsizetype size)
const auto capacityAtEnd = capacity() - d.freeSpaceAtBegin();
if (d->needsDetach() || size > capacityAtEnd)
- reallocData(size, d->detachFlags() | Data::GrowsForward);
+ reallocData(size, QArrayData::Grow);
d.size = size;
if (d->allocatedCapacity())
d.data()[size] = 0;
@@ -1700,7 +1701,7 @@ QByteArray &QByteArray::fill(char ch, qsizetype size)
return *this;
}
-void QByteArray::reallocData(qsizetype alloc, Data::ArrayOptions options)
+void QByteArray::reallocData(qsizetype alloc, QArrayData::AllocationOption option)
{
if (!alloc) {
d = DataPointer::fromRawData(&_empty, 0);
@@ -1713,13 +1714,13 @@ void QByteArray::reallocData(qsizetype alloc, Data::ArrayOptions options)
const bool slowReallocatePath = d.freeSpaceAtBegin() > 0;
if (d->needsDetach() || slowReallocatePath) {
- DataPointer dd(Data::allocate(alloc, options), qMin(alloc, d.size));
+ DataPointer dd(Data::allocate(alloc, option), qMin(alloc, d.size));
if (dd.size > 0)
::memcpy(dd.data(), d.data(), dd.size);
dd.data()[dd.size] = 0;
d = dd;
} else {
- d->reallocate(alloc, options & (QArrayData::GrowsBackwards|QArrayData::GrowsForward) ? QArrayData::Grow : QArrayData::KeepSize);
+ d->reallocate(alloc, option);
}
}
@@ -1729,7 +1730,7 @@ void QByteArray::reallocGrowData(qsizetype n)
n = 1;
if (d->needsDetach()) {
- DataPointer dd(DataPointer::allocateGrow(d, n, DataPointer::AllocateAtEnd));
+ DataPointer dd(DataPointer::allocateGrow(d, n, QArrayData::AllocateAtEnd));
dd->copyAppend(d.data(), d.data() + d.size);
dd.data()[dd.size] = 0;
d = dd;
@@ -1936,9 +1937,9 @@ QByteArray &QByteArray::insert(qsizetype i, QByteArrayView data)
sizeToGrow += i - oldSize;
if (d->needsDetach() || (sizeToGrow > d.freeSpaceAtBegin() && sizeToGrow > d.freeSpaceAtEnd())) {
- DataPointer::AllocationPosition pos = DataPointer::AllocateAtEnd;
+ QArrayData::AllocationPosition pos = QArrayData::AllocateAtEnd;
if (oldSize != 0 && i <= (oldSize >> 1))
- pos = DataPointer::AllocateAtBeginning;
+ pos = QArrayData::AllocateAtBeginning;
DataPointer detached(DataPointer::allocateGrow(d, sizeToGrow, pos));
auto where = d.constBegin() + qMin(i, d->size);
@@ -2000,9 +2001,9 @@ QByteArray &QByteArray::insert(qsizetype i, qsizetype count, char ch)
sizeToGrow += i - oldSize;
if (d->needsDetach() || (sizeToGrow > d.freeSpaceAtBegin() && sizeToGrow > d.freeSpaceAtEnd())) {
- DataPointer::AllocationPosition pos = DataPointer::AllocateAtEnd;
+ QArrayData::AllocationPosition pos = QArrayData::AllocateAtEnd;
if (oldSize != 0 && i <= (oldSize >> 1))
- pos = DataPointer::AllocateAtBeginning;
+ pos = QArrayData::AllocateAtBeginning;
DataPointer detached(DataPointer::allocateGrow(d, sizeToGrow, pos));
auto where = d.constBegin() + qMin(i, d->size);