[llvm] [Offload][NFCI] Avoid temporary string copies in InfoTreeNode (PR #159372)

Alexey Sachkov via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 17 08:34:20 PDT 2025


================
@@ -192,17 +192,16 @@ struct InfoTreeNode {
   llvm::DenseMap<DeviceInfo, size_t> DeviceInfoMap;
 
   InfoTreeNode() : InfoTreeNode("", std::monostate{}, "") {}
-  InfoTreeNode(std::string Key, VariantType Value, std::string Units)
-      : Key(Key), Value(Value), Units(Units) {}
+  InfoTreeNode(std::string &&Key, VariantType Value, std::string &&Units)
----------------
AlexeySachkov wrote:

> What you have is technically correct for moving, but makes the interface 'move only' which isn't as great.

Ok, I see. I postponed the `std::string` construction till the very last moment, but what we could do is to construct it as early as possible and then just `move` it "internally" since we already operate on a copy and that would make the interface more flexible (i.e. non-'move-only'), right?

Does this apply to the constructor as well, or only to the `add` method?

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


More information about the llvm-commits mailing list