[lld] [lld] Add explicit std::move(...) to avoid a few vector copies (PR #180474)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Feb 8 23:43:58 PST 2026
https://github.com/serge-sans-paille created https://github.com/llvm/llvm-project/pull/180474
In corner cases, it is profitable to move an llvm::SmallString instead of copying it.
It is almost always profitable to move an std::vector
Changes suggested by performance-use-std-move from https://github.com/llvm/llvm-project/pull/179467
>From 6baa408fb5a191a33d29ab88d6cc2323e9e461da Mon Sep 17 00:00:00 2001
From: serge-sans-paille <sguelton at mozilla.com>
Date: Mon, 9 Feb 2026 08:38:39 +0100
Subject: [PATCH] [lld] Add explicit std::move(...) to avoid a few vector
copies
In corner cases, it is profitable to move an llvm::SmallString instead of
copying it.
It is almost always profitable to move an std::vector
Changes suggested by performance-use-std-move from https://github.com/llvm/llvm-project/pull/179467
---
lld/COFF/Driver.cpp | 2 +-
lld/wasm/OutputSections.cpp | 2 +-
lld/wasm/Writer.cpp | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/lld/COFF/Driver.cpp b/lld/COFF/Driver.cpp
index 3bc9c98bcdbc3..699d53ca6d2e3 100644
--- a/lld/COFF/Driver.cpp
+++ b/lld/COFF/Driver.cpp
@@ -1339,7 +1339,7 @@ void LinkerDriver::parsePDBAltPath() {
cursor = secondMark + 1;
}
- ctx.config.pdbAltPath = buf;
+ ctx.config.pdbAltPath = std::move(buf);
}
/// Convert resource files and potentially merge input resource object
diff --git a/lld/wasm/OutputSections.cpp b/lld/wasm/OutputSections.cpp
index 8ccd38f7895cb..d6348e459d31e 100644
--- a/lld/wasm/OutputSections.cpp
+++ b/lld/wasm/OutputSections.cpp
@@ -232,7 +232,7 @@ void CustomSection::finalizeInputSections() {
return;
mergedSection->finalizeContents();
- inputSections = newSections;
+ inputSections = std::move(newSections);
}
void CustomSection::finalizeContents() {
diff --git a/lld/wasm/Writer.cpp b/lld/wasm/Writer.cpp
index a184cdbdfefa8..40a5832056087 100644
--- a/lld/wasm/Writer.cpp
+++ b/lld/wasm/Writer.cpp
@@ -1109,7 +1109,7 @@ void Writer::combineOutputSegments() {
}
}
- segments = newSegments;
+ segments = std::move(newSegments);
}
static void createFunction(DefinedFunction *func, StringRef bodyContent) {
More information about the llvm-commits
mailing list