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>bb10
parent
81ee6e763e
commit
50ab7c16d4
|
|
@ -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';
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue