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

@@ -3180,17 +3180,14 @@ void EditorManager::openEditorAtSearchResult(const SearchResultItem &item,
OpenEditorFlags flags, OpenEditorFlags flags,
bool *newEditor) bool *newEditor)
{ {
if (item.path().empty()) { const QStringList &path = item.path();
if (path.isEmpty()) {
openEditor(FilePath::fromUserInput(item.lineText()), editorId, flags, newEditor); openEditor(FilePath::fromUserInput(item.lineText()), editorId, flags, newEditor);
return; return;
} }
const Search::TextPosition position = item.mainRange().begin;
openEditorAt({FilePath::fromUserInput(item.path().first()), openEditorAt({FilePath::fromUserInput(path.first()), position.line, position.column},
item.mainRange().begin.line, editorId, flags, newEditor);
item.mainRange().begin.column},
editorId,
flags,
newEditor);
} }
/*! /*!

View File

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

View File

@@ -268,7 +268,7 @@ void PyLSClient::updateExtraCompilerContents(ExtraCompiler *compiler, const File
void PyLSClient::closeExtraCompiler(ProjectExplorer::ExtraCompiler *compiler) void PyLSClient::closeExtraCompiler(ProjectExplorer::ExtraCompiler *compiler)
{ {
const FilePath file = compiler->targets().first(); const FilePath file = compiler->targets().constFirst();
m_extraCompilerOutputDir.pathAppended(file.fileName()).removeFile(); m_extraCompilerOutputDir.pathAppended(file.fileName()).removeFile();
compiler->disconnect(this); compiler->disconnect(this);
} }

View File

@@ -484,7 +484,7 @@ FilePaths BaseFileFind::replaceAll(const QString &text,
QHash<FilePath, QList<SearchResultItem> > changes; QHash<FilePath, QList<SearchResultItem> > changes;
for (const SearchResultItem &item : items) 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 // Checking for files without write permissions
QSet<FilePath> roFiles; QSet<FilePath> roFiles;

View File

@@ -102,7 +102,7 @@ QTextCursor SnippetOverlay::nextSelectionCursor(const QTextCursor &cursor) const
if (selections[selectionIndex].m_cursor_begin.position() > cursor.position()) if (selections[selectionIndex].m_cursor_begin.position() > cursor.position())
return cursorForIndex(selectionIndex); 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 // currently not over a variable simply select the next available one
for (const OverlaySelection &candidate : selections) { 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()) if (selections.at(equivalents.at(i)).m_cursor_end.position() < cursor.position())
return cursorForIndex(equivalents.at(i)); 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 // currently not over a variable simply select the previous available one
for (int i = selections.size() - 1; i >= 0; --i) { for (int i = selections.size() - 1; i >= 0; --i) {