Skip to content

Commit

Permalink
Use rcpputils::find_and_replace instead of std::regex_replace (ros2#272)
Browse files Browse the repository at this point in the history
The rcpputils implementation is more performant.

Signed-off-by: Jacob Perron <jacob@openrobotics.org>
  • Loading branch information
jacobperron authored and YuSheng committed Jul 31, 2019
1 parent 6eeeff0 commit 58660ed
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
3 changes: 3 additions & 0 deletions rmw_opensplice_cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ if(NOT rosidl_typesupport_opensplice_cpp_FOUND OR NOT rosidl_typesupport_openspl
return()
endif()

find_package(rcpputils REQUIRED)
find_package(rcutils REQUIRED)
find_package(rmw REQUIRED)
find_package(rosidl_generator_c REQUIRED)
find_package(rosidl_generator_cpp REQUIRED)

ament_export_dependencies(
rcpputils
rcutils
rmw
rosidl_generator_c
Expand Down Expand Up @@ -80,6 +82,7 @@ add_library(rmw_opensplice_cpp SHARED
src/types.cpp
)
ament_target_dependencies(rmw_opensplice_cpp
"rcpputils"
"rcutils"
"rmw"
"rosidl_generator_c"
Expand Down
1 change: 1 addition & 0 deletions rmw_opensplice_cpp/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<buildtool_export_depend>opensplice_cmake_module</buildtool_export_depend>
<buildtool_export_depend>rosidl_cmake</buildtool_export_depend>

<build_depend>rcpputils</build_depend>
<build_depend>rcutils</build_depend>
<build_depend>libopensplice69</build_depend>
<build_depend>rmw</build_depend>
Expand Down
6 changes: 3 additions & 3 deletions rmw_opensplice_cpp/src/demangle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
// limitations under the License.

#include <algorithm>
#include <regex>
#include <string>
#include <vector>

#include "rcpputils/find_and_replace.hpp"
#include "rcutils/logging_macros.h"

#include "namespace_prefix.hpp"
Expand Down Expand Up @@ -48,7 +48,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;
Expand Down Expand Up @@ -145,7 +145,7 @@ _demangle_service_type_only(const std::string & dds_type_name)
// everything checks out, reformat it from '[namespace::]dds_::<type><suffix>'
// to '[namespace/]<type>'
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;
Expand Down

0 comments on commit 58660ed

Please sign in to comment.