Don't call non-const methods on temporary QList

Otherwise it may unnecessarily detach. Either store a local
const reference or call const equivalent (e.g. constFirst()).

Change-Id: I96d665487cf28c17e72bea17f1b8f164ce06cc70
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Jarek Kobus
2022-12-07 19:31:39 +01:00
parent 8e7e1dd5f2
commit c021fb5179
5 changed files with 15 additions and 17 deletions

View File

@@ -281,13 +281,14 @@ QFuture<FileSearchResultList> GitGrep::executeSearch(const TextEditor::FileFindP
IEditor *GitGrep::openEditor(const SearchResultItem &item,
const TextEditor::FileFindParameters &parameters)
{
GitGrepParameters params = parameters.searchEngineParameters.value<GitGrepParameters>();
if (params.ref.isEmpty() || item.path().isEmpty())
const GitGrepParameters params = parameters.searchEngineParameters.value<GitGrepParameters>();
const QStringList &itemPath = item.path();
if (params.ref.isEmpty() || itemPath.isEmpty())
return nullptr;
const QString path = QDir::fromNativeSeparators(item.path().first());
const QString path = QDir::fromNativeSeparators(itemPath.first());
const FilePath topLevel = FilePath::fromString(parameters.additionalParameters.toString());
IEditor *editor = m_client->openShowEditor(
topLevel, params.ref, path, GitClient::ShowEditor::OnlyIfDifferent);
IEditor *editor = m_client->openShowEditor(topLevel, params.ref, path,
GitClient::ShowEditor::OnlyIfDifferent);
if (editor)
editor->gotoLine(item.mainRange().begin.line, item.mainRange().begin.column);
return editor;