From 98e50a18eda614caeadaeb7a05fc2f5ab4f735e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Abecasis?= Date: Wed, 4 Apr 2012 14:11:14 +0200 Subject: Simplify conditionals alloc >= size is an invariant of both QString and QByteArray, unless string data is immutable (e.g., when using fromRawData()), in which case alloc will be 0, regardless of size, That's what needs to be checked here. Change-Id: Ief9e6a52a1d5ea1941d23ed3c141edfd15d2a6a7 Reviewed-by: Marius Storm-Olsen Reviewed-by: Thiago Macieira --- src/corelib/tools/qbytearray.cpp | 2 +- src/corelib/tools/qstring.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/corelib') diff --git a/src/corelib/tools/qbytearray.cpp b/src/corelib/tools/qbytearray.cpp index 2e9c1fb801..a6bb6afe57 100644 --- a/src/corelib/tools/qbytearray.cpp +++ b/src/corelib/tools/qbytearray.cpp @@ -1433,7 +1433,7 @@ void QByteArray::resize(int size) if (d->ref.isShared() || size > int(d->alloc) || (!d->capacityReserved && size < d->size && size < int(d->alloc) >> 1)) reallocData(size, true); - if (int(d->alloc) >= size) { + if (d->alloc) { d->size = size; d->data()[size] = '\0'; } diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp index e6a4826c2c..5e69a13057 100644 --- a/src/corelib/tools/qstring.cpp +++ b/src/corelib/tools/qstring.cpp @@ -1243,7 +1243,7 @@ void QString::resize(int size) if (d->ref.isShared() || size > int(d->alloc) || (!d->capacityReserved && size < d->size && size < int(d->alloc) >> 1)) reallocData(size, true); - if (int(d->alloc) >= size) { + if (d->alloc) { d->size = size; d->data()[size] = '\0'; } -- cgit v1.2.3