Skip to content

Commit

Permalink
Use handle_name_ variable instead of allocating for every get_name
Browse files Browse the repository at this point in the history
…call
  • Loading branch information
saikishor committed Aug 22, 2024
1 parent 40ea191 commit e5b69de
Showing 1 changed file with 11 additions and 6 deletions.
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

0 comments on commit e5b69de

Please sign in to comment.