summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools
diff options
context:
space:
mode:
authorAndrei Golubev <andrei.golubev@qt.io>2020-09-02 15:35:07 +0200
committerAndrei Golubev <andrei.golubev@qt.io>2020-09-07 15:50:03 +0200
commit6239246ea8b30a2fce03c65239cc112d7e338578 (patch)
treec2104f780732ff61be254cd8fc1a0a88d4a02d4e /src/corelib/tools
parent08c70ca0ccd70af5442330db62f5bcffaeb89aad (diff)
QCommonArrayOps: append when inserting into empty container
Ensured append is chosen instead of prepend for corner cases when inserting into an empty container Mirrored the logic in shouldGrowBeforeInsert function Task-number: QTBUG-84320 Change-Id: I1c963a2588c331029e450fe55001bbf324f65fb4 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/corelib/tools')
-rw-r--r--src/corelib/tools/qarraydataops.h6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/corelib/tools/qarraydataops.h b/src/corelib/tools/qarraydataops.h
index 9fdf0738e1..db795e2413 100644
--- a/src/corelib/tools/qarraydataops.h
+++ b/src/corelib/tools/qarraydataops.h
@@ -1320,7 +1320,7 @@ public:
const qsizetype freeAtEnd = this->freeSpaceAtEnd();
const qsizetype capacity = this->constAllocatedCapacity();
- if (where == this->begin()) { // prepend
+ if (this->size > 0 && where == this->begin()) { // prepend
// Qt5 QList in prepend: not enough space at begin && 33% full
// Now (below):
return freeAtBegin < n && (this->size >= (capacity / 3));
@@ -1420,7 +1420,7 @@ public:
Q_ASSERT(e <= where || b > this->end() || where == this->end()); // No overlap or append
Q_ASSERT(size_t(e - b) <= this->allocatedCapacity() - this->size);
- if (where == this->begin()) { // prepend case - special space arrangement
+ if (this->size > 0 && where == this->begin()) { // prepend case - special space arrangement
prepareSpaceForPrepend(b, e, e - b); // ### perf. loss
Base::insert(GrowsBackwardsTag{}, this->begin(), b, e);
return;
@@ -1445,7 +1445,7 @@ public:
Q_ASSERT(where >= this->begin() && where <= this->end());
Q_ASSERT(this->allocatedCapacity() - size_t(this->size) >= n);
- if (where == this->begin()) { // prepend case - special space arrangement
+ if (this->size > 0 && where == this->begin()) { // prepend case - special space arrangement
// Preserve the value, because it might be a reference to some part of the moved chunk
T tmp(t);
prepareSpaceForPrepend(n); // ### perf. loss