[clang] [clang] Add explicit std::move(...) to avoid a few copies (PR #180478)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Feb 9 00:00:34 PST 2026
https://github.com/serge-sans-paille created https://github.com/llvm/llvm-project/pull/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
>From 5eb8b4fc4e3db298b3c5815454f72ee36caea45a Mon Sep 17 00:00:00 2001
From: serge-sans-paille <sguelton at mozilla.com>
Date: Mon, 9 Feb 2026 08:57:02 +0100
Subject: [PATCH] [clang] Add explicit std::move(...) to avoid a few copies
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
---
clang/lib/Frontend/ASTUnit.cpp | 2 +-
clang/lib/Frontend/LayoutOverrideSource.cpp | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/clang/lib/Frontend/ASTUnit.cpp b/clang/lib/Frontend/ASTUnit.cpp
index ee22e16bc202d..60433fd7a2f39 100644
--- a/clang/lib/Frontend/ASTUnit.cpp
+++ b/clang/lib/Frontend/ASTUnit.cpp
@@ -1476,7 +1476,7 @@ ASTUnit::create(std::shared_ptr<CompilerInvocation> CI,
ConfigureDiags(Diags, *AST, CaptureDiagnostics);
IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS =
createVFSFromCompilerInvocation(*CI, *Diags);
- AST->DiagOpts = DiagOpts;
+ AST->DiagOpts = std::move(DiagOpts);
AST->Diagnostics = Diags;
AST->FileSystemOpts = CI->getFileSystemOpts();
AST->Invocation = std::move(CI);
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