[clang] [Clang][NFC] Avoid repeating copy of std::string in lambda implementation (PR #153863)

Eli Friedman via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 15 13:53:11 PDT 2025


================
@@ -204,8 +204,9 @@ class FullDependencyConsumer : public DependencyConsumer {
       std::optional<P1689ModuleInfo> Provided,
       std::vector<P1689ModuleInfo> Requires) override {
     ModuleName = Provided ? Provided->ModuleName : "";
-    llvm::transform(Requires, std::back_inserter(NamedModuleDeps),
-                    [](const auto &Module) { return Module.ModuleName; });
+    llvm::transform(
+        Requires, std::back_inserter(NamedModuleDeps),
+        [](const auto &Module) -> const auto & { return Module.ModuleName; });
----------------
efriedma-quic wrote:

Ultimately, you're doing a copy either way: you're inserting a string into an `std::vector<std::string>`.  At best this saves a move constructor call.

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


More information about the cfe-commits mailing list