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

Joseph Huber via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 17 07:38:46 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)
----------------
jhuber6 wrote:

```suggestion
  InfoTreeNode(std::string Key, VariantType Value, std::string Units)
```
I'm pretty sure the typical idiom is to pass-by-value and then move. This should move an r-value into `Key` and then move it into the member. What you have is technically correct for moving, but makes the interface 'move only' which isn't as great.

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


More information about the llvm-commits mailing list