summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2012-06-19 17:31:00 +0200
committerLars Knoll <lars.knoll@qt.io>2019-12-08 18:19:50 +0100
commit746ab4bbd6ebf2147ce93390738c8a71d6a4a335 (patch)
tree7e336ac6bb2c84323867cf7efb02a8ec9243c032 /tests/auto/corelib
parentb42a2b3c3338a320a438bc081cb885fd4547f01f (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/corelib')
-rw-r--r--tests/auto/corelib/text/qstring/tst_qstring.cpp16
1 files changed, 7 insertions, 9 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;