[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:44:30 PST 2026


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-lld-coff

Author: None (serge-sans-paille)

<details>
<summary>Changes</summary>

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

---
Full diff: https://github.com/llvm/llvm-project/pull/180474.diff


3 Files Affected:

- (modified) lld/COFF/Driver.cpp (+1-1) 
- (modified) lld/wasm/OutputSections.cpp (+1-1) 
- (modified) lld/wasm/Writer.cpp (+1-1) 


``````````diff
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) {

``````````

</details>


https://github.com/llvm/llvm-project/pull/180474


More information about the llvm-commits mailing list