summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2015-10-12 22:47:13 +0200
committerJoerg Bornemann <joerg.bornemann@theqtcompany.com>2016-01-06 13:07:31 +0000
commit50ab7c16d470dbb0984bc2b48c5f49d94106edd0 (patch)
treeff49f785c3ac46e89f9eccf81c83274289c473a2 /src/corelib/tools
parent81ee6e763efc4cb7cac12a9f91578776e9b05a3c (diff)
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 <lars.knoll@theqtcompany.com>
Diffstat (limited to 'src/corelib/tools')
-rw-r--r--src/corelib/tools/qstring.cpp19
1 files changed, 5 insertions, 14 deletions
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';
}
}