Don't use iterators to temporary containers

Fix a clazy warning, like:
Don't call QVector::begin() on temporary [clazy-temporary-iterator]

Indeed, we may pass begin and end iterators for 2 different
instances of temporary vector (shared though).

In addition: use const iterators.

Change-Id: Iac1055d9fc226f1b48ca72ee4f3aab433addfe7f
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
Jarek Kobus
2020-11-18 12:25:51 +01:00
parent f7fa53d29b
commit c9f5ce51e0
3 changed files with 12 additions and 15 deletions

View File

@@ -166,15 +166,13 @@ void QmlPreviewPlugin::setLanguageLocale(const QString &locale)
QObject *QmlPreviewPlugin::getPreviewPlugin() QObject *QmlPreviewPlugin::getPreviewPlugin()
{ {
const QVector<ExtensionSystem::PluginSpec *> specs = ExtensionSystem::PluginManager::plugins(); const QVector<ExtensionSystem::PluginSpec *> &specs = ExtensionSystem::PluginManager::plugins();
const auto pluginIt = std::find_if(specs.cbegin(), specs.cend(),
auto pluginIt = std::find_if(specs.begin(),
specs.end(),
[](const ExtensionSystem::PluginSpec *p) { [](const ExtensionSystem::PluginSpec *p) {
return p->name() == "QmlPreview"; return p->name() == "QmlPreview";
}); });
if (pluginIt != specs.end()) if (pluginIt != specs.cend())
return (*pluginIt)->plugin(); return (*pluginIt)->plugin();
return nullptr; return nullptr;

View File

@@ -76,13 +76,13 @@
namespace { namespace {
QObject *getPreviewPlugin() QObject *getPreviewPlugin()
{ {
auto pluginIt = std::find_if(ExtensionSystem::PluginManager::plugins().begin(), const QVector<ExtensionSystem::PluginSpec *> &specs = ExtensionSystem::PluginManager::plugins();
ExtensionSystem::PluginManager::plugins().end(), const auto pluginIt = std::find_if(specs.cbegin(), specs.cend(),
[](const ExtensionSystem::PluginSpec *p) { [](const ExtensionSystem::PluginSpec *p) {
return p->name() == "QmlPreview"; return p->name() == "QmlPreview";
}); });
if (pluginIt != ExtensionSystem::PluginManager::plugins().constEnd()) if (pluginIt != specs.cend())
return (*pluginIt)->plugin(); return (*pluginIt)->plugin();
return nullptr; return nullptr;

View File

@@ -35,13 +35,12 @@
static bool isMultilanguagePresent() static bool isMultilanguagePresent()
{ {
const QVector<ExtensionSystem::PluginSpec *> specs = ExtensionSystem::PluginManager::plugins(); const QVector<ExtensionSystem::PluginSpec *> &specs = ExtensionSystem::PluginManager::plugins();
return std::find_if(specs.begin(), return std::find_if(specs.cbegin(), specs.cend(),
specs.end(),
[](ExtensionSystem::PluginSpec *spec) { [](ExtensionSystem::PluginSpec *spec) {
return spec->name() == "MultiLanguage"; return spec->name() == "MultiLanguage";
}) })
!= specs.end(); != specs.cend();
} }
static Utils::FilePath getMultilanguageDatabaseFilePath(ProjectExplorer::Target *target) static Utils::FilePath getMultilanguageDatabaseFilePath(ProjectExplorer::Target *target)
@@ -57,13 +56,13 @@ static Utils::FilePath getMultilanguageDatabaseFilePath(ProjectExplorer::Target
static QObject *getPreviewPlugin() static QObject *getPreviewPlugin()
{ {
auto pluginIt = std::find_if(ExtensionSystem::PluginManager::plugins().begin(), const QVector<ExtensionSystem::PluginSpec *> &specs = ExtensionSystem::PluginManager::plugins();
ExtensionSystem::PluginManager::plugins().end(), const auto pluginIt = std::find_if(specs.cbegin(), specs.cend(),
[](const ExtensionSystem::PluginSpec *p) { [](const ExtensionSystem::PluginSpec *p) {
return p->name() == "QmlPreview"; return p->name() == "QmlPreview";
}); });
if (pluginIt != ExtensionSystem::PluginManager::plugins().constEnd()) if (pluginIt != specs.cend())
return (*pluginIt)->plugin(); return (*pluginIt)->plugin();
return nullptr; return nullptr;