summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qbytearray.cpp
diff options
context:
space:
mode:
authorJoão Abecasis <joao.abecasis@nokia.com>2012-04-06 09:24:37 +0200
committerQt by Nokia <qt-info@nokia.com>2012-04-16 15:50:59 +0200
commit78b780b9a1ca402ee1f9762f617bb4163684ff34 (patch)
tree8e724da80424c94edc3bbd3273e731fd4efb3deb /src/corelib/tools/qbytearray.cpp
parent2ac4c463afdb8a62b0abb8ba444f34ca50e8979c (diff)
Remove explicit checks for shared_null/empty
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 <thiago.macieira@intel.com> Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@nokia.com>
Diffstat (limited to 'src/corelib/tools/qbytearray.cpp')
-rw-r--r--src/corelib/tools/qbytearray.cpp12
1 files changed, 6 insertions, 6 deletions
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;