diff options
author | Oswald Buddenhagen <oswald.buddenhagen@gmx.de> | 2020-09-11 11:11:45 +0200 |
---|---|---|
committer | MÃ¥rten Nordheim <marten.nordheim@qt.io> | 2020-09-28 22:08:40 +0200 |
commit | b9290cb6e58b47542306c32872e5f53b1c61beee (patch) | |
tree | 1c1b6313217ea4578dac6c2046005938aa533568 /src/corelib/text/qstring.h | |
parent | 7ee9bfc158a290776f622f62d0202220c6d159bc (diff) |
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>
Diffstat (limited to 'src/corelib/text/qstring.h')
-rw-r--r-- | src/corelib/text/qstring.h | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/src/corelib/text/qstring.h b/src/corelib/text/qstring.h index f4e58e38b2..fc3a0431ff 100644 --- a/src/corelib/text/qstring.h +++ b/src/corelib/text/qstring.h @@ -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); |