From 50ab7c16d470dbb0984bc2b48c5f49d94106edd0 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Mon, 12 Oct 2015 22:47:13 +0200 Subject: QString: prevent resize() from shedding capacity ...even if reserve() hasn't been called before. [ChangeLog][QtCore][QString] resize() will no longer shrink the capacity. That means resize(0) now reliably preserves capacity(). Change-Id: If499a20990bbf3a20553da14e50a42918d310c9f Reviewed-by: Lars Knoll --- src/corelib/tools/qstring.cpp | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) (limited to 'src/corelib/tools') diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp index 8c06ec4045..89d9889b2f 100644 --- a/src/corelib/tools/qstring.cpp +++ b/src/corelib/tools/qstring.cpp @@ -1676,20 +1676,11 @@ void QString::resize(int size) return; } - if (size == 0 && !d->capacityReserved) { - Data *x = Data::allocate(0); - if (!d->ref.deref()) - Data::deallocate(d); - d = x; - } else { - if (d->ref.isShared() || uint(size) + 1u > d->alloc - || (!d->capacityReserved && size < d->size - && uint(size) + 1u < uint(d->alloc >> 1))) - reallocData(uint(size) + 1u, true); - if (d->alloc) { - d->size = size; - d->data()[size] = '\0'; - } + if (d->ref.isShared() || uint(size) + 1u > d->alloc) + reallocData(uint(size) + 1u, true); + if (d->alloc) { + d->size = size; + d->data()[size] = '\0'; } } -- cgit v1.2.3