diff options
author | Mårten Nordheim <marten.nordheim@qt.io> | 2020-09-01 11:10:40 +0200 |
---|---|---|
committer | Mårten Nordheim <marten.nordheim@qt.io> | 2020-09-03 14:15:32 +0200 |
commit | 8eef75f0b52519f15078c29dfde5354ca7cccbdb (patch) | |
tree | ecba814a391c93dc2f33af7d02e7dcaf625d51cc /src/corelib/tools | |
parent | 69d239ef00c57baf5af5c760bfedd5344d1d0090 (diff) |
QList/QByteArray/QString: Base GrowsBackwards heuristic on old size
If you grow from 10 to 100 characters then even if the point of
insertion was the end then it will get the GrowsBackwards option on
realloc. By basing it on the oldSize the intention of the position to
insert at is better clarified.
Change-Id: Ia73f4902e8356d94709556de5704cbfa0e1a3a56
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/corelib/tools')
-rw-r--r-- | src/corelib/tools/qlist.h | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/src/corelib/tools/qlist.h b/src/corelib/tools/qlist.h index e94c108f0c..a704de54ea 100644 --- a/src/corelib/tools/qlist.h +++ b/src/corelib/tools/qlist.h @@ -616,7 +616,7 @@ QList<T>::insert(qsizetype i, qsizetype n, parameter_type t) const bool shouldGrow = d->shouldGrowBeforeInsert(d.begin() + i, n); if (d->needsDetach() || newSize > d->allocatedCapacity() || shouldGrow) { typename Data::ArrayOptions flags = d->detachFlags() | Data::GrowsForward; - if (size_t(i) <= newSize / 4) + if (i <= d.size / 4) flags |= Data::GrowsBackwards; DataPointer detached(DataPointer::allocateGrow(d, newSize, flags)); @@ -648,7 +648,7 @@ QList<T>::emplace(qsizetype i, Args&&... args) const size_t newSize = size() + 1; if (d->needsDetach() || newSize > d->allocatedCapacity() || shouldGrow) { typename Data::ArrayOptions flags = d->detachFlags() | Data::GrowsForward; - if (size_t(i) <= newSize / 4) + if (i <= d.size / 4) flags |= Data::GrowsBackwards; DataPointer detached(DataPointer::allocateGrow(d, newSize, flags)); |