Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions offload/plugins-nextgen/common/include/PluginInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
InfoTreeNode(std::string &&Key, VariantType Value, std::string &&Units)
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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understood it correctly, the concern should be resolved in 663d2e1

: Key(std::move(Key)), Value(Value), Units(std::move(Units)) {}

/// Add a new info entry as a child of this node. The entry requires at least
/// a key string in \p Key. The value in \p Value is optional and can be any
/// type that is representable as a string. The units in \p Units is optional
/// and must be a string. Providing a device info key allows liboffload to
/// use that value for an appropriate olGetDeviceInfo query
template <typename T = std::monostate>
InfoTreeNode *add(std::string Key, T Value = T(),
const std::string &Units = std::string(),
InfoTreeNode *add(std::string &&Key, T Value = T(), std::string &&Units = "",
std::optional<DeviceInfo> DeviceInfoKey = std::nullopt) {
assert(!Key.empty() && "Invalid info key");

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

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

if (DeviceInfoKey)
DeviceInfoMap[*DeviceInfoKey] = Children->size() - 1;
Expand Down
Loading