summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2019-11-18 08:44:40 +0100
committerLars Knoll <lars.knoll@qt.io>2020-05-17 20:37:48 +0200
commitb800f3039a754f67466df5e195e70ea2821f9404 (patch)
treef9400663020dc307e927971c640888b4721246cc
parent88c72d972a2b33acf6382107d4aa5ddb4af0d6ec (diff)
Cleanup qUncompress
Cleanup the code in qUncompress and make use of QArrayDataPointer to keep track of memory. Change-Id: I2c11f0468813698d2b7c25acd0f8786a289739a0 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
-rw-r--r--src/corelib/text/qbytearray.cpp29
1 files changed, 8 insertions, 21 deletions
diff --git a/src/corelib/text/qbytearray.cpp b/src/corelib/text/qbytearray.cpp
index 4d86205488..f8c2759507 100644
--- a/src/corelib/text/qbytearray.cpp
+++ b/src/corelib/text/qbytearray.cpp
@@ -692,14 +692,6 @@ QByteArray qCompress(const uchar* data, int nbytes, int compressionLevel)
*/
#ifndef QT_NO_COMPRESS
-namespace {
-struct QByteArrayDataDeleter
-{
- static inline void cleanup(QTypedArrayData<char> *d)
- { if (d) QTypedArrayData<char>::deallocate(d); }
-};
-}
-
static QByteArray invalidCompressedData()
{
qWarning("qUncompress: Input data is corrupted");
@@ -733,24 +725,22 @@ QByteArray qUncompress(const uchar* data, int nbytes)
return invalidCompressedData();
}
- QPair<QByteArray::Data *, char *> pair = QByteArray::Data::allocate(expectedSize + 1);
- QScopedPointer<QByteArray::Data, QByteArrayDataDeleter> d(pair.first);
+ QByteArray::DataPointer d(QByteArray::Data::allocate(expectedSize + 1));
if (Q_UNLIKELY(d.data() == nullptr))
return invalidCompressedData();
forever {
ulong alloc = len;
-
- int res = ::uncompress((uchar*)pair.second, &len,
+ int res = ::uncompress((uchar*)d.data(), &len,
data+4, nbytes-4);
switch (res) {
case Z_OK: {
Q_ASSERT(len <= alloc);
- Q_UNUSED(alloc);
- QByteArray::DataPointer dataPtr = { d.take(), pair.second, uint(len) };
- pair.second[len] = '\0';
- return QByteArray(dataPtr);
+ Q_UNUSED(alloc)
+ d.data()[len] = '\0';
+ d.size = len;
+ return QByteArray(d);
}
case Z_MEM_ERROR:
@@ -764,12 +754,9 @@ QByteArray qUncompress(const uchar* data, int nbytes)
return invalidCompressedData();
} else {
// grow the block
- pair = QByteArray::Data::reallocateUnaligned(d.data(), pair.second, len + 1);
- Q_CHECK_PTR(pair.first);
- if (Q_UNLIKELY(pair.first == nullptr))
+ d->reallocate(d->allocatedCapacity()*2, QByteArray::Data::GrowsForward);
+ if (Q_UNLIKELY(d.data() == nullptr))
return invalidCompressedData();
- d.take(); // don't free
- d.reset(pair.first);
}
continue;