From 19b09affee8698f80d386e3b286753974f6bf10a Mon Sep 17 00:00:00 2001 From: Vladimir Belyavsky Date: Mon, 22 Apr 2024 18:16:24 +0300 Subject: QtQml: Use QHash/QMap's constFind() to avoid unnecessary detaches Use QHash/QMap's constFind() instead of non-const find() where applicable to avoid unnecessary detaches. Change-Id: I6b31af1d163d11deb229681ff7e2f6c9f8335d8c Reviewed-by: Ulf Hermann --- src/qml/qml/qqmlcomponent.cpp | 4 ++-- src/qml/qml/qqmlengine_p.h | 4 ++-- src/qml/qml/qqmlimport.cpp | 4 ++-- src/qml/qml/qqmlmetatype.cpp | 8 ++++---- 4 files changed, 10 insertions(+), 10 deletions(-) (limited to 'src/qml/qml') diff --git a/src/qml/qml/qqmlcomponent.cpp b/src/qml/qml/qqmlcomponent.cpp index c7b9b15bc6..e063418de4 100644 --- a/src/qml/qml/qqmlcomponent.cpp +++ b/src/qml/qml/qqmlcomponent.cpp @@ -1222,8 +1222,8 @@ QQmlProperty QQmlComponentPrivate::removePropertyFromRequired( Q_ASSERT(data && data->propertyCache); targetProp = data->propertyCache->property(targetProp->coreIndex()); } - auto it = requiredProperties->find({createdComponent, targetProp}); - if (it != requiredProperties->end()) { + auto it = requiredProperties->constFind({createdComponent, targetProp}); + if (it != requiredProperties->cend()) { if (wasInRequiredProperties) *wasInRequiredProperties = true; requiredProperties->erase(it); diff --git a/src/qml/qml/qqmlengine_p.h b/src/qml/qml/qqmlengine_p.h index 4b38db9ec9..7c820679ba 100644 --- a/src/qml/qml/qqmlengine_p.h +++ b/src/qml/qml/qqmlengine_p.h @@ -207,8 +207,8 @@ public: QQmlGadgetPtrWrapper *valueTypeInstance(QMetaType type) { int typeIndex = type.id(); - auto it = cachedValueTypeInstances.find(typeIndex); - if (it != cachedValueTypeInstances.end()) + auto it = cachedValueTypeInstances.constFind(typeIndex); + if (it != cachedValueTypeInstances.cend()) return *it; if (QQmlValueType *valueType = QQmlMetaType::valueType(type)) { diff --git a/src/qml/qml/qqmlimport.cpp b/src/qml/qml/qqmlimport.cpp index 7002140362..86380294ba 100644 --- a/src/qml/qml/qqmlimport.cpp +++ b/src/qml/qml/qqmlimport.cpp @@ -527,8 +527,8 @@ QQmlDirScripts QQmlImportInstance::getVersionedScripts(const QQmlDirScripts &qml && (!version.hasMinorVersion() || (sit->version.minorVersion() <= version.minorVersion()))) { // Load the highest version that matches - QMap::iterator vit = versioned.find(sit->nameSpace); - if (vit == versioned.end() + const auto vit = versioned.constFind(sit->nameSpace); + if (vit == versioned.cend() || (vit->version.minorVersion() < sit->version.minorVersion())) { versioned.insert(sit->nameSpace, *sit); } diff --git a/src/qml/qml/qqmlmetatype.cpp b/src/qml/qml/qqmlmetatype.cpp index a21c225eba..1175bde3db 100644 --- a/src/qml/qml/qqmlmetatype.cpp +++ b/src/qml/qml/qqmlmetatype.cpp @@ -668,10 +668,10 @@ QQmlType QQmlMetaType::findCompositeType( QQmlMetaTypeDataPtr data; bool urlExists = true; - auto found = data->urlToType.find(normalized); - if (found == data->urlToType.end()) { - found = data->urlToNonFileImportType.find(normalized); - if (found == data->urlToNonFileImportType.end()) + auto found = data->urlToType.constFind(normalized); + if (found == data->urlToType.cend()) { + found = data->urlToNonFileImportType.constFind(normalized); + if (found == data->urlToNonFileImportType.cend()) urlExists = false; } -- cgit v1.2.3