summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJarek Kobus <jaroslaw.kobus@qt.io>2022-12-07 19:31:39 +0100
committerJarek Kobus <jaroslaw.kobus@qt.io>2022-12-08 10:21:57 +0000
commitc021fb5179eae952e1d46509536f6096e4fb165e (patch)
treea3ad94c16fc7b9bb1bf08106b1cb389999d975ae
parent8e7e1dd5f2e3d0179b9b49c2914a87b09006a12c (diff)
downloadqt-creator-c021fb5179eae952e1d46509536f6096e4fb165e.tar.gz
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>
-rw-r--r--src/plugins/coreplugin/editormanager/editormanager.cpp13
-rw-r--r--src/plugins/git/gitgrep.cpp11
-rw-r--r--src/plugins/python/pythonlanguageclient.cpp2
-rw-r--r--src/plugins/texteditor/basefilefind.cpp2
-rw-r--r--src/plugins/texteditor/snippets/snippetoverlay.cpp4
5 files changed, 15 insertions, 17 deletions
diff --git a/src/plugins/coreplugin/editormanager/editormanager.cpp b/src/plugins/coreplugin/editormanager/editormanager.cpp
index 4a7cdd3d13..b7ecb8b0b8 100644
--- a/src/plugins/coreplugin/editormanager/editormanager.cpp
+++ b/src/plugins/coreplugin/editormanager/editormanager.cpp
@@ -3180,17 +3180,14 @@ void EditorManager::openEditorAtSearchResult(const SearchResultItem &item,
OpenEditorFlags flags,
bool *newEditor)
{
- if (item.path().empty()) {
+ const QStringList &path = item.path();
+ if (path.isEmpty()) {
openEditor(FilePath::fromUserInput(item.lineText()), editorId, flags, newEditor);
return;
}
-
- openEditorAt({FilePath::fromUserInput(item.path().first()),
- item.mainRange().begin.line,
- item.mainRange().begin.column},
- editorId,
- flags,
- newEditor);
+ const Search::TextPosition position = item.mainRange().begin;
+ openEditorAt({FilePath::fromUserInput(path.first()), position.line, position.column},
+ editorId, flags, newEditor);
}
/*!
diff --git a/src/plugins/git/gitgrep.cpp b/src/plugins/git/gitgrep.cpp
index 243952c2d4..dc74c7bc43 100644
--- a/src/plugins/git/gitgrep.cpp
+++ b/src/plugins/git/gitgrep.cpp
@@ -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;
diff --git a/src/plugins/python/pythonlanguageclient.cpp b/src/plugins/python/pythonlanguageclient.cpp
index ce8d254ba7..f4b6a0d52f 100644
--- a/src/plugins/python/pythonlanguageclient.cpp
+++ b/src/plugins/python/pythonlanguageclient.cpp
@@ -268,7 +268,7 @@ void PyLSClient::updateExtraCompilerContents(ExtraCompiler *compiler, const File
void PyLSClient::closeExtraCompiler(ProjectExplorer::ExtraCompiler *compiler)
{
- const FilePath file = compiler->targets().first();
+ const FilePath file = compiler->targets().constFirst();
m_extraCompilerOutputDir.pathAppended(file.fileName()).removeFile();
compiler->disconnect(this);
}
diff --git a/src/plugins/texteditor/basefilefind.cpp b/src/plugins/texteditor/basefilefind.cpp
index 12c635a119..627119048f 100644
--- a/src/plugins/texteditor/basefilefind.cpp
+++ b/src/plugins/texteditor/basefilefind.cpp
@@ -484,7 +484,7 @@ FilePaths BaseFileFind::replaceAll(const QString &text,
QHash<FilePath, QList<SearchResultItem> > changes;
for (const SearchResultItem &item : items)
- changes[FilePath::fromUserInput(item.path().first())].append(item);
+ changes[FilePath::fromUserInput(item.path().constFirst())].append(item);
// Checking for files without write permissions
QSet<FilePath> roFiles;
diff --git a/src/plugins/texteditor/snippets/snippetoverlay.cpp b/src/plugins/texteditor/snippets/snippetoverlay.cpp
index 6824c0470a..05a2391ae6 100644
--- a/src/plugins/texteditor/snippets/snippetoverlay.cpp
+++ b/src/plugins/texteditor/snippets/snippetoverlay.cpp
@@ -102,7 +102,7 @@ QTextCursor SnippetOverlay::nextSelectionCursor(const QTextCursor &cursor) const
if (selections[selectionIndex].m_cursor_begin.position() > cursor.position())
return cursorForIndex(selectionIndex);
}
- return cursorForIndex(m_variables[nextVariableIndex].first());
+ return cursorForIndex(m_variables[nextVariableIndex].constFirst());
}
// currently not over a variable simply select the next available one
for (const OverlaySelection &candidate : selections) {
@@ -128,7 +128,7 @@ QTextCursor SnippetOverlay::previousSelectionCursor(const QTextCursor &cursor) c
if (selections.at(equivalents.at(i)).m_cursor_end.position() < cursor.position())
return cursorForIndex(equivalents.at(i));
}
- return cursorForIndex(m_variables[previousVariableIndex].last());
+ return cursorForIndex(m_variables[previousVariableIndex].constLast());
}
// currently not over a variable simply select the previous available one
for (int i = selections.size() - 1; i >= 0; --i) {