diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2012-06-14 15:05:34 +0200 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2019-12-08 10:29:42 +0100 |
commit | add048bc4eee8e4422fe2b434b4b817f56693d33 (patch) | |
tree | c83275a8046a64b38ce474a1f9a6f2297526aab5 /src/corelib/text | |
parent | f2569c0ff75eb9a8418bb065c33c318f0a44c8ed (diff) |
Start moving QArrayData's size and data pointer to the main class
This requires that the allocation functions return two pointers: the d
pointer and the pointer to the actual data.
Ported QArrayDataPointer & SimpleVector to the inlined size & data.
For now, the size and offset members are not yet removed from
QArrayData, to let QVector, QByteArray and QString compile unmodified.
Change-Id: I8489300976723d75b8fd5831427b1e2bba486196
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/corelib/text')
-rw-r--r-- | src/corelib/text/qbytearray.cpp | 29 | ||||
-rw-r--r-- | src/corelib/text/qstring.cpp | 28 |
2 files changed, 29 insertions, 28 deletions
diff --git a/src/corelib/text/qbytearray.cpp b/src/corelib/text/qbytearray.cpp index 78395a47e3..7562227d7d 100644 --- a/src/corelib/text/qbytearray.cpp +++ b/src/corelib/text/qbytearray.cpp @@ -731,7 +731,7 @@ QByteArray qUncompress(const uchar* data, int nbytes) return invalidCompressedData(); } - QScopedPointer<QByteArray::Data, QByteArrayDataDeleter> d(QByteArray::Data::allocate(expectedSize + 1)); + QScopedPointer<QByteArray::Data, QByteArrayDataDeleter> d(QByteArray::Data::allocate(expectedSize + 1).first); if (Q_UNLIKELY(d.data() == nullptr)) return invalidCompressedData(); @@ -764,7 +764,8 @@ QByteArray qUncompress(const uchar* data, int nbytes) return invalidCompressedData(); } else { // grow the block - QByteArray::Data *p = QByteArray::Data::reallocateUnaligned(d.data(), len + 1); + char *dataPointer = d->data(); + QByteArray::Data *p = QByteArray::Data::reallocateUnaligned(d.data(), dataPointer, len + 1).first; if (Q_UNLIKELY(p == nullptr)) return invalidCompressedData(); d.take(); // don't free @@ -1204,7 +1205,7 @@ QByteArray &QByteArray::operator=(const char *str) if (!str) { x = Data::sharedNull(); } else if (!*str) { - x = Data::allocate(0); + x = Data::allocate(0).first; } else { const int len = int(strlen(str)); const int fullLen = len + 1; @@ -1693,9 +1694,9 @@ QByteArray::QByteArray(const char *data, int size) if (size < 0) size = int(strlen(data)); if (!size) { - d = Data::allocate(0); + d = Data::allocate(0).first; } else { - d = Data::allocate(uint(size) + 1u); + d = Data::allocate(uint(size) + 1u).first; Q_CHECK_PTR(d); d->size = size; memcpy(d->data(), data, size); @@ -1714,9 +1715,9 @@ QByteArray::QByteArray(const char *data, int size) QByteArray::QByteArray(int size, char ch) { if (size <= 0) { - d = Data::allocate(0); + d = Data::allocate(0).first; } else { - d = Data::allocate(uint(size) + 1u); + d = Data::allocate(uint(size) + 1u).first; Q_CHECK_PTR(d); d->size = size; memset(d->data(), ch, size); @@ -1732,7 +1733,7 @@ QByteArray::QByteArray(int size, char ch) QByteArray::QByteArray(int size, Qt::Initialization) { - d = Data::allocate(uint(size) + 1u); + d = Data::allocate(uint(size) + 1u).first; Q_CHECK_PTR(d); d->size = size; d->data()[size] = '\0'; @@ -1769,7 +1770,7 @@ void QByteArray::resize(int size) // which is used in place of the Qt 3 idiom: // QByteArray a(sz); // - Data *x = Data::allocate(uint(size) + 1u); + Data *x = Data::allocate(uint(size) + 1u).first; Q_CHECK_PTR(x); x->size = size; x->data()[size] = '\0'; @@ -1806,7 +1807,7 @@ QByteArray &QByteArray::fill(char ch, int size) void QByteArray::reallocData(uint alloc, Data::ArrayOptions options) { if (d->needsDetach()) { - Data *x = Data::allocate(alloc, options); + Data *x = Data::allocate(alloc, options).first; Q_CHECK_PTR(x); x->size = qMin(int(alloc) - 1, d->size); ::memcpy(x->data(), d->data(), x->size); @@ -1815,7 +1816,7 @@ void QByteArray::reallocData(uint alloc, Data::ArrayOptions options) Data::deallocate(d); d = x; } else { - Data *x = Data::reallocateUnaligned(d, alloc, options); + Data *x = Data::reallocateUnaligned(d, d->data(), alloc, options).first; Q_CHECK_PTR(x); d = x; } @@ -3130,7 +3131,7 @@ QByteArray QByteArray::mid(int pos, int len) const return QByteArray(); case QContainerImplHelper::Empty: { - QByteArrayDataPtr empty = { Data::allocate(0) }; + QByteArrayDataPtr empty = { Data::allocate(0).first }; return QByteArray(empty); } case QContainerImplHelper::Full: @@ -4444,9 +4445,9 @@ QByteArray QByteArray::fromRawData(const char *data, int size) if (!data) { x = Data::sharedNull(); } else if (!size) { - x = Data::allocate(0); + x = Data::allocate(0).first; } else { - x = Data::fromRawData(data, size); + x = Data::fromRawData(data, size).ptr; Q_CHECK_PTR(x); } QByteArrayDataPtr dataPtr = { x }; diff --git a/src/corelib/text/qstring.cpp b/src/corelib/text/qstring.cpp index 4d3f2016ac..8ae365338d 100644 --- a/src/corelib/text/qstring.cpp +++ b/src/corelib/text/qstring.cpp @@ -2109,9 +2109,9 @@ QString::QString(const QChar *unicode, int size) ++size; } if (!size) { - d = Data::allocate(0); + d = Data::allocate(0).first; } else { - d = Data::allocate(size + 1); + d = Data::allocate(size + 1).first; Q_CHECK_PTR(d); d->size = size; memcpy(d->data(), unicode, size * sizeof(QChar)); @@ -2129,9 +2129,9 @@ QString::QString(const QChar *unicode, int size) QString::QString(int size, QChar ch) { if (size <= 0) { - d = Data::allocate(0); + d = Data::allocate(0).first; } else { - d = Data::allocate(size + 1); + d = Data::allocate(size + 1).first; Q_CHECK_PTR(d); d->size = size; d->data()[size] = '\0'; @@ -2151,7 +2151,7 @@ QString::QString(int size, QChar ch) */ QString::QString(int size, Qt::Initialization) { - d = Data::allocate(size + 1); + d = Data::allocate(size + 1).first; Q_CHECK_PTR(d); d->size = size; d->data()[size] = '\0'; @@ -2169,7 +2169,7 @@ QString::QString(int size, Qt::Initialization) */ QString::QString(QChar ch) { - d = Data::allocate(2); + d = Data::allocate(2).first; Q_CHECK_PTR(d); d->size = 1; d->data()[0] = ch.unicode(); @@ -2354,7 +2354,7 @@ void QString::reallocData(uint alloc, bool grow) allocOptions |= QArrayData::GrowsForward; if (d->needsDetach()) { - Data *x = Data::allocate(alloc, allocOptions); + Data *x = Data::allocate(alloc, allocOptions).first; Q_CHECK_PTR(x); x->size = qMin(int(alloc) - 1, d->size); ::memcpy(x->data(), d->data(), x->size * sizeof(QChar)); @@ -2363,7 +2363,7 @@ void QString::reallocData(uint alloc, bool grow) Data::deallocate(d); d = x; } else { - Data *p = Data::reallocateUnaligned(d, alloc, allocOptions); + Data *p = Data::reallocateUnaligned(d, d->data(), alloc, allocOptions).first; Q_CHECK_PTR(p); d = p; } @@ -4898,7 +4898,7 @@ QString QString::mid(int position, int n) const return QString(); case QContainerImplHelper::Empty: { - QStringDataPtr empty = { Data::allocate(0) }; + QStringDataPtr empty = { Data::allocate(0).first }; return QString(empty); } case QContainerImplHelper::Full: @@ -5354,11 +5354,11 @@ QString::Data *QString::fromLatin1_helper(const char *str, int size) if (!str) { d = Data::sharedNull(); } else if (size == 0 || (!*str && size < 0)) { - d = Data::allocate(0); + d = Data::allocate(0).first; } else { if (size < 0) size = qstrlen(str); - d = Data::allocate(size + 1); + d = Data::allocate(size + 1).first; Q_CHECK_PTR(d); d->size = size; d->data()[size] = '\0'; @@ -5418,7 +5418,7 @@ QString QString::fromLocal8Bit_helper(const char *str, int size) if (!str) return QString(); if (size == 0 || (!*str && size < 0)) { - QStringDataPtr empty = { Data::allocate(0) }; + QStringDataPtr empty = { Data::allocate(0).first }; return QString(empty); } #if QT_CONFIG(textcodec) @@ -9124,9 +9124,9 @@ QString QString::fromRawData(const QChar *unicode, int size) if (!unicode) { x = Data::sharedNull(); } else if (!size) { - x = Data::allocate(0); + x = Data::allocate(0).first; } else { - x = Data::fromRawData(reinterpret_cast<const ushort *>(unicode), size); + x = Data::fromRawData(reinterpret_cast<const ushort *>(unicode), size).ptr; Q_CHECK_PTR(x); } QStringDataPtr dataPtr = { x }; |