Skip to content

Commit 7183afa

Browse files
committed
[Offload][NFCI] Avoid temporary string copies in InfoTreeNode
It looks like all all sites of `InfoTreeNode::add` pass string literals as `Key` and `Units`, so we could mandate those to be rvalue-references to move them directly into the final location, avoiding temporary copies.
1 parent 1c2d7b3 commit 7183afa

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -192,17 +192,16 @@ struct InfoTreeNode {
192192
llvm::DenseMap<DeviceInfo, size_t> DeviceInfoMap;
193193

194194
InfoTreeNode() : InfoTreeNode("", std::monostate{}, "") {}
195-
InfoTreeNode(std::string Key, VariantType Value, std::string Units)
196-
: Key(Key), Value(Value), Units(Units) {}
195+
InfoTreeNode(std::string &&Key, VariantType Value, std::string &&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
200200
/// type that is representable as a string. The units in \p Units is optional
201201
/// and must be a string. Providing a device info key allows liboffload to
202202
/// use that value for an appropriate olGetDeviceInfo query
203203
template <typename T = std::monostate>
204-
InfoTreeNode *add(std::string Key, T Value = T(),
205-
const std::string &Units = std::string(),
204+
InfoTreeNode *add(std::string &&Key, T Value = T(), std::string &&Units = "",
206205
std::optional<DeviceInfo> DeviceInfoKey = std::nullopt) {
207206
assert(!Key.empty() && "Invalid info key");
208207

@@ -217,7 +216,8 @@ struct InfoTreeNode {
217216
else
218217
ValueVariant = std::string{Value};
219218

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

222222
if (DeviceInfoKey)
223223
DeviceInfoMap[*DeviceInfoKey] = Children->size() - 1;

0 commit comments

Comments
 (0)