From 08c70ca0ccd70af5442330db62f5bcffaeb89aad Mon Sep 17 00:00:00 2001 From: Andrei Golubev Date: Fri, 4 Sep 2020 11:27:44 +0200 Subject: QList/QString/QByteArray: no prepend optimized allocation when empty Scoped prepend optimized allocation to only work when prepending into a non-empty container. Otherwise, even appends would be considered prepends since d.size == 0 when container is empty This is, of course, not good for prepend cases but we prefer appends over prepends. My proposal is to figure out what's the best strategy based on use cases and performance measurements. For now, let's just make sure appends are not additionally pessimized Anyhow, this is an implementation detail and should not be considered behavior change (at least not the one that is user noticeable) Task-number: QTBUG-84320 Change-Id: Ibed616a2afa9bc24f78252f15a617bf92e2c6ea3 Reviewed-by: Lars Knoll --- src/corelib/text/qbytearray.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/corelib/text/qbytearray.cpp') diff --git a/src/corelib/text/qbytearray.cpp b/src/corelib/text/qbytearray.cpp index 8cc45d4500..1eb5162fb1 100644 --- a/src/corelib/text/qbytearray.cpp +++ b/src/corelib/text/qbytearray.cpp @@ -1942,7 +1942,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 <= oldSize / 4) // using QList's policy + if (oldSize != 0 && i <= oldSize / 4) // using QList's policy flags |= Data::GrowsBackwards; reallocGrowData(newSize + 1, flags); } -- cgit v1.2.3