From 3854660e96d6c0f1d8354f809c91c3943d4c2e5c Mon Sep 17 00:00:00 2001 From: Yadu Date: Mon, 24 Jun 2024 09:27:39 -0700 Subject: [PATCH 1/2] Update rmw_zenoh_cpp/src/rmw_zenoh.cpp Co-authored-by: Chris Lalancette Signed-off-by: Yadu --- rmw_zenoh_cpp/src/rmw_zenoh.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rmw_zenoh_cpp/src/rmw_zenoh.cpp b/rmw_zenoh_cpp/src/rmw_zenoh.cpp index fc33bc7f..428b7b9a 100644 --- a/rmw_zenoh_cpp/src/rmw_zenoh.cpp +++ b/rmw_zenoh_cpp/src/rmw_zenoh.cpp @@ -84,7 +84,7 @@ std::string strip_slashes(const char * const str) if (str[end] == '/') { --end; } - return ret.substr(start, end - start); + return ret.substr(start, end - start + 1); } //============================================================================== From 50d7339473b4c80e328d69f1b2cbd6e096e0a02f Mon Sep 17 00:00:00 2001 From: Yadunund Date: Tue, 25 Jun 2024 01:47:45 +0800 Subject: [PATCH 2/2] Avoid one allocation Signed-off-by: Yadunund --- rmw_zenoh_cpp/src/rmw_zenoh.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/rmw_zenoh_cpp/src/rmw_zenoh.cpp b/rmw_zenoh_cpp/src/rmw_zenoh.cpp index 428b7b9a..f844cfa9 100644 --- a/rmw_zenoh_cpp/src/rmw_zenoh.cpp +++ b/rmw_zenoh_cpp/src/rmw_zenoh.cpp @@ -102,10 +102,13 @@ z_owned_keyexpr_t ros_topic_name_to_zenoh_key( const char * const topic_type, const char * const type_hash) { - const std::string keyexpr_str = std::to_string(domain_id) + "/" + - strip_slashes(topic_name) + "/" + - std::string(topic_type) + "/" + - std::string(type_hash); + std::string keyexpr_str = std::to_string(domain_id); + keyexpr_str += "/"; + keyexpr_str += strip_slashes(topic_name); + keyexpr_str += "/"; + keyexpr_str += topic_type; + keyexpr_str += "/"; + keyexpr_str += type_hash; return z_keyexpr_new(keyexpr_str.c_str()); }