From 78b780b9a1ca402ee1f9762f617bb4163684ff34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Abecasis?= Date: Fri, 6 Apr 2012 09:24:37 +0200 Subject: Remove explicit checks for shared_null/empty MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This eases porting to QArrayData and retains semantics. In append() and prepend() a conditional was generalized so that no work is done if there is nothing to add. Done-with: Jędrzej Nowacki Change-Id: Ib9e7bb572801b2434fa040cde2bf66dacf595f22 Reviewed-by: Thiago Macieira Reviewed-by: Jędrzej Nowacki --- src/corelib/tools/qbytearray.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/corelib/tools/qbytearray.cpp') diff --git a/src/corelib/tools/qbytearray.cpp b/src/corelib/tools/qbytearray.cpp index 1e1fb7903c..13b5230caf 100644 --- a/src/corelib/tools/qbytearray.cpp +++ b/src/corelib/tools/qbytearray.cpp @@ -1412,7 +1412,7 @@ void QByteArray::resize(int size) if (!d->ref.deref()) free(d); d = x; - } else if (d == &shared_null.ba || d == &shared_empty.ba) { + } else if (d->size == 0 && d->ref.isStatic()) { // // Optimize the idiom: // QByteArray a; @@ -1536,9 +1536,9 @@ QByteArray QByteArray::nulTerminated() const QByteArray &QByteArray::prepend(const QByteArray &ba) { - if ((d == &shared_null.ba || d == &shared_empty.ba) && !IS_RAW_DATA(ba.d)) { + if (d->size == 0 && d->ref.isStatic() && !IS_RAW_DATA(ba.d)) { *this = ba; - } else if (ba.d != &shared_null.ba) { + } else if (ba.d->size != 0) { QByteArray tmp = *this; *this = ba; append(tmp); @@ -1620,9 +1620,9 @@ QByteArray &QByteArray::prepend(char ch) QByteArray &QByteArray::append(const QByteArray &ba) { - if ((d == &shared_null.ba || d == &shared_empty.ba) && !IS_RAW_DATA(ba.d)) { + if (d->size == 0 && d->ref.isStatic() && !IS_RAW_DATA(ba.d)) { *this = ba; - } else if (ba.d != &shared_null.ba) { + } else if (ba.d->size != 0) { if (d->ref.isShared() || uint(d->size + ba.d->size) + 1u > d->alloc) reallocData(uint(d->size + ba.d->size) + 1u, true); memcpy(d->data() + d->size, ba.d->data(), ba.d->size); @@ -2663,7 +2663,7 @@ QByteArray QByteArray::right(int len) const QByteArray QByteArray::mid(int pos, int len) const { - if (d == &shared_null.ba || d == &shared_empty.ba || pos > d->size) + if ((d->size == 0 && d->ref.isStatic()) || pos > d->size) return QByteArray(); if (len < 0) len = d->size - pos; -- cgit v1.2.3