path: root/tests
diff options
authorSimon Hausmann <>2013-12-05 16:59:27 +0100
committerThe Qt Project <>2013-12-06 18:18:44 +0100
commit105d10dea9d790a69595a2e73e8fea80a5d1a3ad (patch)
tree68c8cfb65c6c23ebb44ea1436da4b0c354bd95a2 /tests
parent0c936ca83c40b73f30195a619900f2be98b9e968 (diff)
Fix quadratic behavior in QMetaObjectBuilder when writing string table
QHash::key() is O(n) and we're calling it n times. That can make repeated calls to the meta object builder very slow, as for example QQmlPropertyMap when inserting properties repeatedly. Fortunately this is easy to fix, as the value in the hash map is also the index, so we can simply iterate over the hash once. With the exception of the class name, which we have to treat specially to ensure that it is always the first entry in the string table. Task-number: QTBUG-32720 Change-Id: Ic954c45c454107feee83216131f601cc69d4c63b Reviewed-by: Olivier Goffart <>
Diffstat (limited to 'tests')
1 files changed, 16 insertions, 0 deletions
diff --git a/tests/auto/corelib/kernel/qmetaobjectbuilder/tst_qmetaobjectbuilder.cpp b/tests/auto/corelib/kernel/qmetaobjectbuilder/tst_qmetaobjectbuilder.cpp
index 8f6bd50cca..5cf3e6d97c 100644
--- a/tests/auto/corelib/kernel/qmetaobjectbuilder/tst_qmetaobjectbuilder.cpp
+++ b/tests/auto/corelib/kernel/qmetaobjectbuilder/tst_qmetaobjectbuilder.cpp
@@ -75,6 +75,8 @@ private slots:
void usage_connect();
void usage_templateConnect();
+ void classNameFirstInStringData();
static bool checkForSideEffects
(const QMetaObjectBuilder& builder,
@@ -1694,6 +1696,20 @@ void tst_QMetaObjectBuilder::usage_templateConnect()
+void tst_QMetaObjectBuilder::classNameFirstInStringData()
+ QMetaObjectBuilder builder;
+ builder.addMetaObject(&SomethingOfEverything::staticMetaObject);
+ builder.setClassName(QByteArrayLiteral("TestClass"));
+ QMetaObject *mo = builder.toMetaObject();
+ QByteArrayDataPtr header;
+ header.ptr = const_cast<QByteArrayData*>(mo->d.stringdata);
+ QCOMPARE(QByteArray(header), QByteArrayLiteral("TestClass"));
+ free(mo);
#include "tst_qmetaobjectbuilder.moc"