Skip to content

Commit bb58464

Browse files
[Offload][NFC] Avoid temporary string copies in InfoTreeNode (llvm#159372)
1 parent 8bbd95a commit bb58464

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

offload/plugins-nextgen/common/include/PluginInterface.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ struct InfoTreeNode {
193193

194194
InfoTreeNode() : InfoTreeNode("", std::monostate{}, "") {}
195195
InfoTreeNode(std::string Key, VariantType Value, std::string Units)
196-
: Key(Key), Value(Value), Units(Units) {}
196+
: Key(std::move(Key)), Value(Value), Units(std::move(Units)) {}
197197

198198
/// Add a new info entry as a child of this node. The entry requires at least
199199
/// a key string in \p Key. The value in \p Value is optional and can be any
@@ -202,7 +202,7 @@ struct InfoTreeNode {
202202
/// use that value for an appropriate olGetDeviceInfo query
203203
template <typename T = std::monostate>
204204
InfoTreeNode *add(std::string Key, T Value = T(),
205-
const std::string &Units = std::string(),
205+
std::string Units = std::string(),
206206
std::optional<DeviceInfo> DeviceInfoKey = std::nullopt) {
207207
assert(!Key.empty() && "Invalid info key");
208208

@@ -217,7 +217,8 @@ struct InfoTreeNode {
217217
else
218218
ValueVariant = std::string{Value};
219219

220-
auto Ptr = &Children->emplace_back(Key, ValueVariant, Units);
220+
auto Ptr =
221+
&Children->emplace_back(std::move(Key), ValueVariant, std::move(Units));
221222

222223
if (DeviceInfoKey)
223224
DeviceInfoMap[*DeviceInfoKey] = Children->size() - 1;

0 commit comments

Comments
 (0)