remove bogus QByteArray::resize() optimization

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2021-03-22 08:06:57 +02:00
parent 95d6ba4600
commit 335958f240

View file

@ -1416,25 +1416,7 @@ void QByteArray::resize(int size)
if (!d->ref.deref()) if (!d->ref.deref())
freeData(d); freeData(d);
d = x; d = x;
} else if (d == &shared_null) { } else if (size != d->size) {
//
// Optimize the idiom:
// QByteArray a;
// a.resize(sz);
// ...
// which is used in place of the Qt 3 idiom:
// QByteArray a(sz);
//
Data *x = static_cast<Data *>(malloc(sizeof(Data)+size));
Q_CHECK_PTR(x);
x->ref = 1;
x->alloc = x->size = size;
x->data = x->array;
x->array[size] = '\0';
(void) d->ref.deref(); // cannot be 0, x points to shared_null
d = x;
} else {
if (d->ref != 1 || size != d->size)
reallocData(size); reallocData(size);
d->size = size; d->size = size;
if (d->data == d->array) { if (d->data == d->array) {