diff options
author | Lars Knoll <lars.knoll@digia.com> | 2013-06-25 22:15:08 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-06-28 14:56:01 +0200 |
commit | 553b41c407985e5b18f089679c014d884624afbd (patch) | |
tree | ece372464ed6f417d62ec29c9aebc017e86324e5 /src/qml/qml/qqmlmetatype.cpp | |
parent | e7249321a95d615fa0abea700e9f768b20151fe1 (diff) |
Remove a potentially dangerous optimisation
The code could fail in case the hashing would happen to return
the same value for both strings.
Change-Id: I7c256754b38aafd8c49b9fbbd2f01b9cc0346a2b
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'src/qml/qml/qqmlmetatype.cpp')
-rw-r--r-- | src/qml/qml/qqmlmetatype.cpp | 29 |
1 files changed, 4 insertions, 25 deletions
diff --git a/src/qml/qml/qqmlmetatype.cpp b/src/qml/qml/qqmlmetatype.cpp index b7138e01b3..9a9e6df366 100644 --- a/src/qml/qml/qqmlmetatype.cpp +++ b/src/qml/qml/qqmlmetatype.cpp @@ -215,27 +215,6 @@ public: static QHash<const QMetaObject *, int> attachedPropertyIds; }; -// Avoid multiple fromUtf8(), copies and hashing of the module name. -// This is only called when metaTypeDataLock is locked. -static QHashedString moduleFromUtf8(const char *module) -{ - if (!module) - return QHashedString(); - - static const char *lastModule = 0; - static QHashedString lastModuleStr; - - // Separate plugins may have different strings at the same address - QHashedCStringRef currentModule(module, ::strlen(module)); - if ((lastModule != module) || (lastModuleStr.hash() != currentModule.hash())) { - lastModuleStr = QString::fromUtf8(module); - lastModuleStr.hash(); - lastModule = module; - } - - return lastModuleStr; -} - void QQmlType::SingletonInstanceInfo::init(QQmlEngine *e) { QV4::ExecutionEngine *v4 = QV8Engine::getV4(e->handle()); @@ -346,7 +325,7 @@ QQmlType::QQmlType(int index, const QString &elementName, const QQmlPrivate::Reg : d(new QQmlTypePrivate(SingletonType)) { d->elementName = elementName; - d->module = moduleFromUtf8(type.uri); + d->module = QString::fromUtf8(type.uri); d->version_maj = type.versionMajor; d->version_min = type.versionMinor; @@ -374,7 +353,7 @@ QQmlType::QQmlType(int index, const QString &elementName, const QQmlPrivate::Reg : d(new QQmlTypePrivate(CppType)) { d->elementName = elementName; - d->module = moduleFromUtf8(type.uri); + d->module = QString::fromUtf8(type.uri); d->version_maj = type.versionMajor; d->version_min = type.versionMinor; @@ -413,7 +392,7 @@ QQmlType::QQmlType(int index, const QString &elementName, const QQmlPrivate::Reg d->index = index; d->elementName = elementName; - d->module = moduleFromUtf8(type.uri); + d->module = QString::fromUtf8(type.uri); d->version_maj = type.versionMajor; d->version_min = type.versionMinor; @@ -1162,7 +1141,7 @@ bool checkRegistration(QQmlType::RegistrationType typeType, QQmlMetaTypeData *da } if (uri && !typeName.isEmpty()) { - QString nameSpace = moduleFromUtf8(uri); + QString nameSpace = QString::fromUtf8(uri); if (!data->typeRegistrationNamespace.isEmpty()) { // We can only install types into the registered namespace |