Fix quadratic behavior in QMetaObjectBuilder when writing string table
authorSimon Hausmann <simon.hausmann@digia.com>
Thu, 5 Dec 2013 15:59:27 +0000 (16:59 +0100)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Fri, 6 Dec 2013 17:18:44 +0000 (18:18 +0100)
commit105d10dea9d790a69595a2e73e8fea80a5d1a3ad
tree68c8cfb65c6c23ebb44ea1436da4b0c354bd95a2
parent0c936ca83c40b73f30195a619900f2be98b9e968
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 <ogoffart@woboq.com>
src/corelib/kernel/qmetaobjectbuilder.cpp
src/corelib/kernel/qmetaobjectbuilder_p.h
src/dbus/qdbusmetaobject.cpp
tests/auto/corelib/kernel/qmetaobjectbuilder/tst_qmetaobjectbuilder.cpp