make {QString,QByteArray}::squeeze() work without prior reserve()
string-shortening operations never throw away capacity (unless
detaching), so it may very much make sense to squeeze a string whose
capacity was not explicitly reserved.
this does in fact restore the behavior prior to commit a3aa2fcf, which
changed it presumably only due to not considering the case above.
Change-Id: I0d7919a1724dd3ecc6cd4cbd7236eb52067f0a1c
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>
bb10
parent
7ee9bfc158
commit
b9290cb6e5
|
|
@ -532,7 +532,7 @@ inline void QByteArray::reserve(qsizetype asize)
|
|||
|
||||
inline void QByteArray::squeeze()
|
||||
{
|
||||
if ((d->flags() & Data::CapacityReserved) == 0)
|
||||
if (!d.isMutable())
|
||||
return;
|
||||
if (d->needsDetach() || size() < capacity()) {
|
||||
reallocData(size(), d->detachFlags() & ~Data::CapacityReserved);
|
||||
|
|
|
|||
|
|
@ -1166,9 +1166,9 @@ inline void QString::reserve(qsizetype asize)
|
|||
|
||||
inline void QString::squeeze()
|
||||
{
|
||||
if ((d->flags() & Data::CapacityReserved) == 0)
|
||||
if (!d.isMutable())
|
||||
return;
|
||||
if (d->needsDetach() || d.size < capacity()) {
|
||||
if (d->needsDetach() || size() < capacity()) {
|
||||
reallocData(d.size, d->detachFlags() & ~Data::CapacityReserved);
|
||||
} else {
|
||||
d->clearFlag(Data::CapacityReserved);
|
||||
|
|
|
|||
Loading…
Reference in New Issue