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/text/qbytearray.cpp | |
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/text/qbytearray.cpp')
-rw-r--r-- | src/corelib/text/qbytearray.cpp | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/src/corelib/text/qbytearray.cpp b/src/corelib/text/qbytearray.cpp index 293b8f72fe..27986baeae 100644 --- a/src/corelib/text/qbytearray.cpp +++ b/src/corelib/text/qbytearray.cpp @@ -1962,7 +1962,7 @@ QByteArray &QByteArray::insert(qsizetype i, const char *str, qsizetype len) // ### optimize me if (d->needsDetach() || newSize > capacity() || shouldGrow) { auto flags = d->detachFlags() | Data::GrowsForward; - if (i <= newSize / 4) // using QList's policy + if (i <= oldSize / 4) // using QList's policy flags |= Data::GrowsBackwards; reallocGrowData(newSize + 1, flags); } @@ -2010,7 +2010,7 @@ QByteArray &QByteArray::insert(qsizetype i, qsizetype count, char ch) // ### optimize me if (d->needsDetach() || newSize > capacity() || shouldGrow) { auto flags = d->detachFlags() | Data::GrowsForward; - if (i <= newSize / 4) // using QList's policy + if (i <= oldSize / 4) // using QList's policy flags |= Data::GrowsBackwards; reallocGrowData(newSize + 1, flags); } |