[clang] bcbb04a - [clang] Add explicit std::move(...) to avoid a few copies (#180478)
via cfe-commits
cfe-commits at lists.llvm.org
Sun Feb 15 08:35:02 PST 2026
Author: serge-sans-paille
Date: 2026-02-15T16:34:58Z
New Revision: bcbb04acf5b136b98ce1edf4cbd0de283ca24756
URL: https://github.com/llvm/llvm-project/commit/bcbb04acf5b136b98ce1edf4cbd0de283ca24756
DIFF: https://github.com/llvm/llvm-project/commit/bcbb04acf5b136b98ce1edf4cbd0de283ca24756.diff
LOG: [clang] Add explicit std::move(...) to avoid a few copies (#180478)
Moving an std::shared_ptr is always profitable (marginally).
Moving a clang::LayoutOverrideSource::Layout may be profitable depending
on the size of the underlying llvm::SmallVector.
Changes suggested by performance-use-std-move from #179467
Added:
Modified:
clang/lib/Frontend/ASTUnit.cpp
clang/lib/Frontend/LayoutOverrideSource.cpp
Removed:
################################################################################
diff --git a/clang/lib/Frontend/ASTUnit.cpp b/clang/lib/Frontend/ASTUnit.cpp
index ee22e16bc202d..9fcaf1806fcb1 100644
--- a/clang/lib/Frontend/ASTUnit.cpp
+++ b/clang/lib/Frontend/ASTUnit.cpp
@@ -1476,8 +1476,8 @@ ASTUnit::create(std::shared_ptr<CompilerInvocation> CI,
ConfigureDiags(Diags, *AST, CaptureDiagnostics);
IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS =
createVFSFromCompilerInvocation(*CI, *Diags);
- AST->DiagOpts = DiagOpts;
- AST->Diagnostics = Diags;
+ AST->DiagOpts = std::move(DiagOpts);
+ AST->Diagnostics = std::move(Diags);
AST->FileSystemOpts = CI->getFileSystemOpts();
AST->Invocation = std::move(CI);
AST->FileMgr =
diff --git a/clang/lib/Frontend/LayoutOverrideSource.cpp b/clang/lib/Frontend/LayoutOverrideSource.cpp
index 0a60e00e5cb12..6912b9c112006 100644
--- a/clang/lib/Frontend/LayoutOverrideSource.cpp
+++ b/clang/lib/Frontend/LayoutOverrideSource.cpp
@@ -186,7 +186,7 @@ LayoutOverrideSource::LayoutOverrideSource(StringRef Filename) {
// Flush the last type/layout, if there is one.
if (!CurrentType.empty())
- Layouts[CurrentType] = CurrentLayout;
+ Layouts[CurrentType] = std::move(CurrentLayout);
}
bool
More information about the cfe-commits
mailing list