From 0359896be105157bcbf2e322d800017b36792e53 Mon Sep 17 00:00:00 2001 From: Jacob Perron Date: Fri, 28 Jun 2019 10:16:10 -0700 Subject: [PATCH] Use rcpputils::find_and_replace instead of std::regex_replace (#291) The rcpputils implementation is more performant. Signed-off-by: Jacob Perron --- rmw_fastrtps_dynamic_cpp/CMakeLists.txt | 3 +++ .../rmw_fastrtps_dynamic_cpp/MessageTypeSupport_impl.hpp | 5 +++-- .../rmw_fastrtps_dynamic_cpp/ServiceTypeSupport_impl.hpp | 7 ++++--- rmw_fastrtps_dynamic_cpp/package.xml | 2 ++ rmw_fastrtps_dynamic_cpp/src/type_support_common.hpp | 5 +++-- rmw_fastrtps_shared_cpp/src/demangle.cpp | 6 +++--- 6 files changed, 18 insertions(+), 10 deletions(-) diff --git a/rmw_fastrtps_dynamic_cpp/CMakeLists.txt b/rmw_fastrtps_dynamic_cpp/CMakeLists.txt index c041bb524..f2ac936a8 100644 --- a/rmw_fastrtps_dynamic_cpp/CMakeLists.txt +++ b/rmw_fastrtps_dynamic_cpp/CMakeLists.txt @@ -31,6 +31,7 @@ endif() find_package(ament_cmake_ros REQUIRED) +find_package(rcpputils REQUIRED) find_package(rcutils REQUIRED) find_package(rmw_fastrtps_shared_cpp REQUIRED) @@ -90,6 +91,7 @@ target_link_libraries(rmw_fastrtps_dynamic_cpp # specific order: dependents before dependencies ament_target_dependencies(rmw_fastrtps_dynamic_cpp + "rcpputils" "rcutils" "rosidl_typesupport_fastrtps_c" "rosidl_typesupport_fastrtps_cpp" @@ -116,6 +118,7 @@ ament_export_dependencies(rosidl_typesupport_fastrtps_cpp) ament_export_dependencies(rosidl_typesupport_introspection_cpp) ament_export_dependencies(rosidl_typesupport_introspection_c) ament_export_dependencies(rosidl_generator_c) +ament_export_dependencies(rcpputils) ament_export_dependencies(rcutils) ament_export_dependencies(rmw_fastrtps_shared_cpp) ament_export_dependencies(rmw) diff --git a/rmw_fastrtps_dynamic_cpp/include/rmw_fastrtps_dynamic_cpp/MessageTypeSupport_impl.hpp b/rmw_fastrtps_dynamic_cpp/include/rmw_fastrtps_dynamic_cpp/MessageTypeSupport_impl.hpp index ec94a8a78..b0a26cb13 100644 --- a/rmw_fastrtps_dynamic_cpp/include/rmw_fastrtps_dynamic_cpp/MessageTypeSupport_impl.hpp +++ b/rmw_fastrtps_dynamic_cpp/include/rmw_fastrtps_dynamic_cpp/MessageTypeSupport_impl.hpp @@ -20,10 +20,11 @@ #include #include -#include #include #include +#include "rcpputils/find_and_replace.hpp" + #include "rmw_fastrtps_dynamic_cpp/MessageTypeSupport.hpp" #include "rosidl_typesupport_introspection_cpp/field_types.hpp" @@ -41,7 +42,7 @@ MessageTypeSupport::MessageTypeSupport(const MembersType * members) std::string message_name(this->members_->message_name_); if (!message_namespace.empty()) { // Find and replace C namespace separator with C++, in case this is using C typesupport - message_namespace = std::regex_replace(message_namespace, std::regex("__"), "::"); + message_namespace = rcpputils::find_and_replace(message_namespace, "__", "::"); ss << message_namespace << "::"; } ss << "dds_::" << message_name << "_"; diff --git a/rmw_fastrtps_dynamic_cpp/include/rmw_fastrtps_dynamic_cpp/ServiceTypeSupport_impl.hpp b/rmw_fastrtps_dynamic_cpp/include/rmw_fastrtps_dynamic_cpp/ServiceTypeSupport_impl.hpp index 3d7363ef0..218cbb91e 100644 --- a/rmw_fastrtps_dynamic_cpp/include/rmw_fastrtps_dynamic_cpp/ServiceTypeSupport_impl.hpp +++ b/rmw_fastrtps_dynamic_cpp/include/rmw_fastrtps_dynamic_cpp/ServiceTypeSupport_impl.hpp @@ -18,10 +18,11 @@ #include #include #include -#include #include #include +#include "rcpputils/find_and_replace.hpp" + #include "rmw_fastrtps_dynamic_cpp/ServiceTypeSupport.hpp" #include "rosidl_typesupport_introspection_cpp/field_types.hpp" @@ -45,7 +46,7 @@ RequestTypeSupport::RequestTypeSupport( std::string service_name(members->service_name_); if (!service_namespace.empty()) { // Find and replace C namespace separator with C++, in case this is using C typesupport - service_namespace = std::regex_replace(service_namespace, std::regex("__"), "::"); + service_namespace = rcpputils::find_and_replace(service_namespace, "__", "::"); ss << service_namespace << "::"; } ss << "dds_::" << service_name << "_Request_"; @@ -74,7 +75,7 @@ ResponseTypeSupport::ResponseTypeSupport std::string service_name(members->service_name_); if (!service_namespace.empty()) { // Find and replace C namespace separator with C++, in case this is using C typesupport - service_namespace = std::regex_replace(service_namespace, std::regex("__"), "::"); + service_namespace = rcpputils::find_and_replace(service_namespace, "__", "::"); ss << service_namespace << "::"; } ss << "dds_::" << service_name << "_Response_"; diff --git a/rmw_fastrtps_dynamic_cpp/package.xml b/rmw_fastrtps_dynamic_cpp/package.xml index cb292e936..dd7574340 100644 --- a/rmw_fastrtps_dynamic_cpp/package.xml +++ b/rmw_fastrtps_dynamic_cpp/package.xml @@ -16,6 +16,7 @@ fastcdr fastrtps fastrtps_cmake_module + rcpputils rcutils rmw rmw_fastrtps_shared_cpp @@ -28,6 +29,7 @@ fastcdr fastrtps fastrtps_cmake_module + rcpputils rcutils rmw rmw_fastrtps_shared_cpp diff --git a/rmw_fastrtps_dynamic_cpp/src/type_support_common.hpp b/rmw_fastrtps_dynamic_cpp/src/type_support_common.hpp index 3ace81127..bd9e22d1d 100644 --- a/rmw_fastrtps_dynamic_cpp/src/type_support_common.hpp +++ b/rmw_fastrtps_dynamic_cpp/src/type_support_common.hpp @@ -15,13 +15,14 @@ #ifndef TYPE_SUPPORT_COMMON_HPP_ #define TYPE_SUPPORT_COMMON_HPP_ -#include #include #include #include "fastrtps/Domain.h" #include "fastrtps/participant/Participant.h" +#include "rcpputils/find_and_replace.hpp" + #include "rmw/error_handling.h" #include "rmw_fastrtps_shared_cpp/TypeSupport.hpp" @@ -85,7 +86,7 @@ _create_type_name( std::ostringstream ss; std::string message_namespace(members->message_namespace_); // Find and replace C namespace separator with C++, in case this is using C typesupport - message_namespace = std::regex_replace(message_namespace, std::regex("__"), "::"); + message_namespace = rcpputils::find_and_replace(message_namespace, "__", "::"); std::string message_name(members->message_name_); if (!message_namespace.empty()) { ss << message_namespace << "::"; diff --git a/rmw_fastrtps_shared_cpp/src/demangle.cpp b/rmw_fastrtps_shared_cpp/src/demangle.cpp index e5c28e765..b7a6aba1d 100644 --- a/rmw_fastrtps_shared_cpp/src/demangle.cpp +++ b/rmw_fastrtps_shared_cpp/src/demangle.cpp @@ -13,10 +13,10 @@ // limitations under the License. #include -#include #include #include +#include "rcpputils/find_and_replace.hpp" #include "rcutils/logging_macros.h" #include "rcutils/types.h" @@ -46,7 +46,7 @@ _demangle_if_ros_type(const std::string & dds_type_string) } std::string type_namespace = dds_type_string.substr(0, substring_position); - type_namespace = std::regex_replace(type_namespace, std::regex("::"), "/"); + type_namespace = rcpputils::find_and_replace(type_namespace, "::", "/"); size_t start = substring_position + substring.size(); std::string type_name = dds_type_string.substr(start, dds_type_string.length() - 1 - start); return type_namespace + type_name; @@ -145,7 +145,7 @@ _demangle_service_type_only(const std::string & dds_type_name) // everything checks out, reformat it from '[type_namespace::]dds_::' // to '[type_namespace/]' std::string type_namespace = dds_type_name.substr(0, ns_substring_position); - type_namespace = std::regex_replace(type_namespace, std::regex("::"), "/"); + type_namespace = rcpputils::find_and_replace(type_namespace, "::", "/"); size_t start = ns_substring_position + ns_substring.length(); std::string type_name = dds_type_name.substr(start, suffix_position - start); return type_namespace + type_name;