aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVladimir Belyavsky <belyavskyv@gmail.com>2024-04-22 18:16:24 +0300
committerVladimir Belyavsky <belyavskyv@gmail.com>2024-04-22 20:26:47 +0000
commit19b09affee8698f80d386e3b286753974f6bf10a (patch)
tree9e4d147a36ba22308ad397b455f29478edbe032e
parent7b463868de47c5f08f086e9508cb4b41a310f268 (diff)
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 <ulf.hermann@qt.io>
-rw-r--r--src/qml/jsruntime/qv4engine.cpp12
-rw-r--r--src/qml/jsruntime/qv4executablecompilationunit_p.h4
-rw-r--r--src/qml/qml/qqmlcomponent.cpp4
-rw-r--r--src/qml/qml/qqmlengine_p.h4
-rw-r--r--src/qml/qml/qqmlimport.cpp4
-rw-r--r--src/qml/qml/qqmlmetatype.cpp8
-rw-r--r--src/qmlmodels/qqmldmabstractitemmodeldata.cpp4
-rw-r--r--src/qmlworkerscript/qquickworkerscript.cpp8
8 files changed, 24 insertions, 24 deletions
diff --git a/src/qml/jsruntime/qv4engine.cpp b/src/qml/jsruntime/qv4engine.cpp
index acf6132799..d09dcced19 100644
--- a/src/qml/jsruntime/qv4engine.cpp
+++ b/src/qml/jsruntime/qv4engine.cpp
@@ -2172,15 +2172,15 @@ ExecutionEngine::Module ExecutionEngine::moduleForUrl(
ExecutionEngine::Module ExecutionEngine::loadModule(const QUrl &url, const ExecutableCompilationUnit *referrer)
{
- const auto nativeModule = nativeModules.find(url);
- if (nativeModule != nativeModules.end())
+ const auto nativeModule = nativeModules.constFind(url);
+ if (nativeModule != nativeModules.cend())
return Module { nullptr, *nativeModule };
const QUrl resolved = referrer
? referrer->finalUrl().resolved(QQmlTypeLoader::normalize(url))
: QQmlTypeLoader::normalize(url);
- auto existingModule = m_compilationUnits.find(resolved);
- if (existingModule != m_compilationUnits.end())
+ auto existingModule = m_compilationUnits.constFind(resolved);
+ if (existingModule != m_compilationUnits.cend())
return Module { *existingModule, nullptr };
auto newModule = compileModule(resolved);
@@ -2191,8 +2191,8 @@ ExecutionEngine::Module ExecutionEngine::loadModule(const QUrl &url, const Execu
QV4::Value *ExecutionEngine::registerNativeModule(const QUrl &url, const QV4::Value &module)
{
- const auto existingModule = nativeModules.find(url);
- if (existingModule != nativeModules.end())
+ const auto existingModule = nativeModules.constFind(url);
+ if (existingModule != nativeModules.cend())
return nullptr;
QV4::Value *val = this->memoryManager->m_persistentValues->allocate();
diff --git a/src/qml/jsruntime/qv4executablecompilationunit_p.h b/src/qml/jsruntime/qv4executablecompilationunit_p.h
index a67086e57a..3f3335ef4e 100644
--- a/src/qml/jsruntime/qv4executablecompilationunit_p.h
+++ b/src/qml/jsruntime/qv4executablecompilationunit_p.h
@@ -268,8 +268,8 @@ private:
IdentifierHash ExecutableCompilationUnit::namedObjectsPerComponent(int componentObjectIndex)
{
- auto it = namedObjectsPerComponentCache.find(componentObjectIndex);
- if (Q_UNLIKELY(it == namedObjectsPerComponentCache.end()))
+ auto it = namedObjectsPerComponentCache.constFind(componentObjectIndex);
+ if (Q_UNLIKELY(it == namedObjectsPerComponentCache.cend()))
return createNamedObjectsPerComponent(componentObjectIndex);
Q_ASSERT(!it->isEmpty());
return *it;
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<QString, QQmlDirParser::Script>::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;
}
diff --git a/src/qmlmodels/qqmldmabstractitemmodeldata.cpp b/src/qmlmodels/qqmldmabstractitemmodeldata.cpp
index 901d8bbe53..bf4a0226b1 100644
--- a/src/qmlmodels/qqmldmabstractitemmodeldata.cpp
+++ b/src/qmlmodels/qqmldmabstractitemmodeldata.cpp
@@ -67,8 +67,8 @@ void QQmlDMAbstractItemModelData::setValue(const QString &role, const QVariant &
return;
}
- QHash<QByteArray, int>::iterator it = m_type->roleNames.find(role.toUtf8());
- if (it != m_type->roleNames.end()) {
+ const auto it = m_type->roleNames.constFind(role.toUtf8());
+ if (it != m_type->roleNames.cend()) {
for (int i = 0; i < m_type->propertyRoles.size(); ++i) {
if (m_type->propertyRoles.at(i) == *it) {
m_cachedData[i] = value;
diff --git a/src/qmlworkerscript/qquickworkerscript.cpp b/src/qmlworkerscript/qquickworkerscript.cpp
index b4fd21fe7e..f892343b85 100644
--- a/src/qmlworkerscript/qquickworkerscript.cpp
+++ b/src/qmlworkerscript/qquickworkerscript.cpp
@@ -180,8 +180,8 @@ bool QQuickWorkerScriptEnginePrivate::event(QEvent *event)
} else if (event->type() == (QEvent::Type)WorkerRemoveEvent::WorkerRemove) {
QMutexLocker locker(&m_lock);
WorkerRemoveEvent *workerEvent = static_cast<WorkerRemoveEvent *>(event);
- auto itr = workers.find(workerEvent->workerId());
- if (itr != workers.end()) {
+ auto itr = workers.constFind(workerEvent->workerId());
+ if (itr != workers.cend()) {
if (itr->isT1())
delete itr->asT1();
workers.erase(itr);
@@ -417,8 +417,8 @@ int QQuickWorkerScriptEngine::registerWorkerScript(QQuickWorkerScript *owner)
void QQuickWorkerScriptEngine::removeWorkerScript(int id)
{
- const auto it = d->workers.find(id);
- if (it == d->workers.end())
+ const auto it = d->workers.constFind(id);
+ if (it == d->workers.cend())
return;
if (it->isT1()) {