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

Small performance improvments #183

Merged
merged 1 commit into from
Jan 3, 2018
Merged
Show file tree
Hide file tree
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
6 changes: 1 addition & 5 deletions rmw_fastrtps_cpp/src/demangle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@
std::string
_demangle_if_ros_topic(const std::string & topic_name)
{
std::string prefix = _get_ros_prefix_if_exists(topic_name);
if (prefix.length()) {
return topic_name.substr(strlen(ros_topic_prefix));
}
return topic_name;
return _strip_ros_prefix_if_exists(topic_name);
}

/// Return the demangled ROS type or the original if not a ROS type.
Expand Down
16 changes: 14 additions & 2 deletions rmw_fastrtps_cpp/src/namespace_prefix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,22 @@ const std::vector<std::string> _ros_prefixes =
std::string
_get_ros_prefix_if_exists(const std::string & topic_name)
{
for (auto prefix : _ros_prefixes) {
if (topic_name.rfind(std::string(prefix) + "/", 0) == 0) {
for (const auto & prefix : _ros_prefixes) {
if (topic_name.rfind(prefix, 0) == 0 && topic_name.at(prefix.length()) == '/') {
return prefix;
}
}
return "";
}

/// Strip the ROS specific prefix if it exists from the topic name.
std::string
_strip_ros_prefix_if_exists(const std::string & topic_name)
{
for (const auto & prefix : _ros_prefixes) {
if (topic_name.rfind(prefix, 0) == 0 && topic_name.at(prefix.length()) == '/') {
return topic_name.substr(prefix.length());
}
}
return topic_name;
}
3 changes: 3 additions & 0 deletions rmw_fastrtps_cpp/src/namespace_prefix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,7 @@ extern const std::vector<std::string> _ros_prefixes;
std::string
_get_ros_prefix_if_exists(const std::string & topic_name);

/// Returns the topic name stripped of and ROS specific prefix if exists.
std::string
_strip_ros_prefix_if_exists(const std::string & topic_name);
#endif // NAMESPACE_PREFIX_HPP_
8 changes: 4 additions & 4 deletions rmw_fastrtps_cpp/src/rmw_count.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ rmw_count_publishers(
WriterInfo * slave_target = impl->secondaryPubListener;
slave_target->mapmutex.lock();
*count = 0;
for (auto it : slave_target->topicNtypes) {
auto topic_fqdn = _demangle_if_ros_topic(it.first);
for (const auto & it : slave_target->topicNtypes) {
const auto topic_fqdn = _demangle_if_ros_topic(it.first);
if (topic_fqdn == topic_name) {
*count += it.second.size();
}
Expand Down Expand Up @@ -90,8 +90,8 @@ rmw_count_subscribers(
ReaderInfo * slave_target = impl->secondarySubListener;
*count = 0;
slave_target->mapmutex.lock();
for (auto it : slave_target->topicNtypes) {
auto topic_fqdn = _demangle_if_ros_topic(it.first);
for (const auto & it : slave_target->topicNtypes) {
const auto topic_fqdn = _demangle_if_ros_topic(it.first);
if (topic_fqdn == topic_name) {
*count += it.second.size();
}
Expand Down