summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMårten Nordheim <marten.nordheim@qt.io>2020-10-23 12:00:56 +0200
committerMårten Nordheim <marten.nordheim@qt.io>2020-10-28 08:48:23 +0200
commit205629bb6240a4aae52aa62f6f6c9c302148efd2 (patch)
tree16b18f48b9ea58b284a1ae46b1c96bd5ef41bcbc /src
parent2c4874be40aa40b698315cac0ad768e5c650a740 (diff)
QByteArray: make (ap|pre)pend(const QByteArray &) consider reserved
Append was previously optimized for lhs being empty but it should've also taken into account if space had been reserved. Apply the same optimization to prepend while we're at it. Change-Id: I5e5d33a3189b9ad88d45e858a2ac412cbc294f79 Reviewed-by: Andrei Golubev <andrei.golubev@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src')
-rw-r--r--src/corelib/text/qbytearray.cpp8
-rw-r--r--src/corelib/text/qbytearray.h3
2 files changed, 8 insertions, 3 deletions
diff --git a/src/corelib/text/qbytearray.cpp b/src/corelib/text/qbytearray.cpp
index 459e00887d..1ff61ed11a 100644
--- a/src/corelib/text/qbytearray.cpp
+++ b/src/corelib/text/qbytearray.cpp
@@ -1784,6 +1784,12 @@ QByteArray QByteArray::nulTerminated() const
Prepends \a ba to this byte array.
*/
+QByteArray &QByteArray::prepend(const QByteArray &ba)
+{
+ if (size() == 0 && ba.size() > d.constAllocatedCapacity() && ba.d.isMutable())
+ return (*this = ba);
+ return prepend(QByteArrayView(ba));
+}
/*!
\fn QByteArray &QByteArray::prepend(const char *str)
@@ -1842,7 +1848,7 @@ QByteArray QByteArray::nulTerminated() const
QByteArray &QByteArray::append(const QByteArray &ba)
{
- if (size() == 0 && ba.d.isMutable())
+ if (size() == 0 && ba.size() > d.constAllocatedCapacity() && ba.d.isMutable())
return (*this = ba);
return append(QByteArrayView(ba));
}
diff --git a/src/corelib/text/qbytearray.h b/src/corelib/text/qbytearray.h
index 60f1bd01f5..c2d65e2c55 100644
--- a/src/corelib/text/qbytearray.h
+++ b/src/corelib/text/qbytearray.h
@@ -283,8 +283,7 @@ public:
{ return insert(0, QByteArrayView(s, qsizetype(qstrlen(s)))); }
QByteArray &prepend(const char *s, qsizetype len)
{ return insert(0, QByteArrayView(s, len)); }
- QByteArray &prepend(const QByteArray &a)
- { return insert(0, a); }
+ QByteArray &prepend(const QByteArray &a);
QByteArray &prepend(QByteArrayView a)
{ return insert(0, a); }