Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use handle_name_ variable instead of allocating for every get_name call #1706

Merged
merged 2 commits into from
Aug 22, 2024
Merged
Changes from all commits
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
17 changes: 11 additions & 6 deletions hardware_interface/include/hardware_interface/handle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,17 @@ class Handle
Handle(
const std::string & prefix_name, const std::string & interface_name,
double * value_ptr = nullptr)
: prefix_name_(prefix_name), interface_name_(interface_name), value_ptr_(value_ptr)
: prefix_name_(prefix_name),
interface_name_(interface_name),
handle_name_(prefix_name_ + "/" + interface_name_),
value_ptr_(value_ptr)
{
}

explicit Handle(const InterfaceDescription & interface_description)
: prefix_name_(interface_description.prefix_name),
interface_name_(interface_description.interface_info.name)
interface_name_(interface_description.interface_info.name),
handle_name_(prefix_name_ + "/" + interface_name_)
{
// As soon as multiple datatypes are used in HANDLE_DATATYPE
// we need to initialize according the type passed in interface description
Expand All @@ -53,14 +57,14 @@ class Handle
[[deprecated("Use InterfaceDescription for initializing the Interface")]]

explicit Handle(const std::string & interface_name)
: interface_name_(interface_name), value_ptr_(nullptr)
: interface_name_(interface_name), handle_name_("/" + interface_name_), value_ptr_(nullptr)
{
}

[[deprecated("Use InterfaceDescription for initializing the Interface")]]

explicit Handle(const char * interface_name)
: interface_name_(interface_name), value_ptr_(nullptr)
: interface_name_(interface_name), handle_name_("/" + interface_name_), value_ptr_(nullptr)
{
}

Expand All @@ -77,12 +81,12 @@ class Handle
/// Returns true if handle references a value.
inline operator bool() const { return value_ptr_ != nullptr; }

const std::string get_name() const { return prefix_name_ + "/" + interface_name_; }
const std::string & get_name() const { return handle_name_; }

const std::string & get_interface_name() const { return interface_name_; }

[[deprecated(
"Replaced by get_name method, which is semantically more correct")]] const std::string
"Replaced by get_name method, which is semantically more correct")]] const std::string &
get_full_name() const
{
return get_name();
Expand Down Expand Up @@ -111,6 +115,7 @@ class Handle
protected:
std::string prefix_name_;
std::string interface_name_;
std::string handle_name_;
HANDLE_DATATYPE value_;
// BEGIN (Handle export change): for backward compatibility
// TODO(Manuel) redeclare as HANDLE_DATATYPE * value_ptr_ if old functionality is removed
Expand Down
Loading