diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2012-06-19 17:31:00 +0200 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2019-12-08 18:19:50 +0100 |
commit | 746ab4bbd6ebf2147ce93390738c8a71d6a4a335 (patch) | |
tree | 7e336ac6bb2c84323867cf7efb02a8ec9243c032 /tests/auto | |
parent | b42a2b3c3338a320a438bc081cb885fd4547f01f (diff) |
Inline the size and data pointer members in QString
I'd have preferred to use QArrayDataPointer<ushort> for QString, but
that option wasn't the best one. QArrayDataPointer try to do some
operations using QArrayDataOps and that would expand to unnecessary
code. What's more, the existing code expected to be able to modify and
access the d pointer.
Instead, this commit introduces QStringPrivate (named differently from
QStringData to catch potential users), which contains the three
members. This POD class is also used in QJsonValue to store the
"inlined" QString. QHashedString in qtdeclarative will need a similar
solution.
Change-Id: I33f072158e6e2cd031d4d2ffc81f4a8dbaf4e616
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/corelib/text/qstring/tst_qstring.cpp | 16 | ||||
-rw-r--r-- | tests/auto/other/toolsupport/tst_toolsupport.cpp | 4 |
2 files changed, 9 insertions, 11 deletions
diff --git a/tests/auto/corelib/text/qstring/tst_qstring.cpp b/tests/auto/corelib/text/qstring/tst_qstring.cpp index 01376036b7..ad31f9cefc 100644 --- a/tests/auto/corelib/text/qstring/tst_qstring.cpp +++ b/tests/auto/corelib/text/qstring/tst_qstring.cpp @@ -608,8 +608,7 @@ QString verifyZeroTermination(const QString &str) QString::DataPtr strDataPtr = const_cast<QString &>(str).data_ptr(); // Skip if isStatic() or fromRawData(), as those offer no guarantees - if (strDataPtr->isStatic() - || strDataPtr->offset != QString().data_ptr()->offset) + if (strDataPtr.d->isStatic() || !strDataPtr.d->isMutable()) return str; int strSize = str.size(); @@ -620,7 +619,7 @@ QString verifyZeroTermination(const QString &str) .arg(strTerminator.unicode(), 4, 16, QChar('0')); // Skip mutating checks on shared strings - if (strDataPtr->isShared()) + if (strDataPtr.d->isShared()) return str; const QChar *strData = str.constData(); @@ -4070,12 +4069,12 @@ void tst_QString::setRawData() QVERIFY(cstr == QString(ptr, 1)); // This actually tests the recycling of the shared data object - QString::DataPtr csd = cstr.data_ptr(); + void *csd = cstr.data_ptr().d; cstr.setRawData(ptr2, 1); QVERIFY(cstr.isDetached()); QVERIFY(cstr.constData() == ptr2); QVERIFY(cstr == QString(ptr2, 1)); - QVERIFY(cstr.data_ptr() == csd); + QVERIFY(cstr.data_ptr().d == csd); // This tests the discarding of the shared data object cstr = "foo"; @@ -4083,12 +4082,12 @@ void tst_QString::setRawData() QVERIFY(cstr.constData() != ptr2); // Another test of the fallback - csd = cstr.data_ptr(); + csd = cstr.data_ptr().d; cstr.setRawData(ptr2, 1); QVERIFY(cstr.isDetached()); QVERIFY(cstr.constData() == ptr2); QVERIFY(cstr == QString(ptr2, 1)); - QVERIFY(cstr.data_ptr() != csd); + QVERIFY(cstr.data_ptr().d != csd); } void tst_QString::fromStdString() @@ -6637,8 +6636,7 @@ void tst_QString::literals() QVERIFY(str.length() == 4); QVERIFY(str == QLatin1String("abcd")); - QVERIFY(str.data_ptr()->isStatic()); - QVERIFY(str.data_ptr()->offset == sizeof(QStringData)); + QVERIFY(str.data_ptr().d->isStatic()); const QChar *s = str.constData(); QString str2 = str; diff --git a/tests/auto/other/toolsupport/tst_toolsupport.cpp b/tests/auto/other/toolsupport/tst_toolsupport.cpp index 2440b4a5e9..9591eca16a 100644 --- a/tests/auto/other/toolsupport/tst_toolsupport.cpp +++ b/tests/auto/other/toolsupport/tst_toolsupport.cpp @@ -126,9 +126,9 @@ void tst_toolsupport::offsets_data() #ifdef Q_PROCESSOR_X86 // x86 32-bit has weird alignment rules. Refer to QtPrivate::AlignOf in // qglobal.h for more details. - data << 176 << 272; + data << 184 << 288; #else - data << 180 << 272; + data << 188 << 288; #endif } #endif |