Skip to content

Conversation

@ipa-fez
Copy link
Contributor

@ipa-fez ipa-fez commented Feb 4, 2025

This gets rid of the regex based string splitting and just finds the appropriate substring using a delimiter directly.

I came across this because clang-19 raises some -Wmaybe-uninitialized warnings inside the regex code here.

Comment on lines +509 to +525
auto last_slash = lookup_name.find_last_of('/');
auto last_colon = lookup_name.find_last_of(':');
if (last_slash == std::string::npos && last_colon == std::string::npos) {
// no matches
return lookup_name;
}
if (last_slash == std::string::npos) {
// only colon matched
return lookup_name.substr(last_colon + 1);
}
if (last_colon == std::string::npos) {
// only slash matched
return lookup_name.substr(last_slash + 1);
}
// both matched, return shorter suffix
return lookup_name.substr(std::max(last_slash, last_colon) + 1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the PR!

Please add unit tests for ClassLoader<T>::getName so we can make sure the code works the same before and after the refactor
https://github.com/ros/pluginlib/blob/rolling/test/utest.cpp

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added some tests and the missing include. Let me know if I should add any additional test cases.

@ipa-fez ipa-fez force-pushed the refactor/no_regex branch 2 times, most recently from 3c0d559 to 1f8f369 Compare February 5, 2025 15:11
Signed-off-by: Felix Zeltner <28302109+ipa-fez@users.noreply.github.com>
@ahcorde ahcorde requested a review from sloretz October 2, 2025 13:35
@ahcorde
Copy link
Contributor

ahcorde commented Oct 2, 2025

@sloretz do you mind to review it again ?

@ahcorde
Copy link
Contributor

ahcorde commented Oct 2, 2025

Pulls: #271
Gist: https://gist.githubusercontent.com/ahcorde/c27f1f20602ca5b504f85a4970d0a9e3/raw/9775f1461f8c32c825ac7bedae7402b9e21f351e/ros2.repos
BUILD args: --packages-above-and-dependencies pluginlib
TEST args: --packages-above pluginlib
ROS Distro: rolling
Job: ci_launcher
ci_launcher ran: https://ci.ros2.org/job/ci_launcher/17147

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Linux-rhel Build Status
  • Windows Build Status

@ahcorde
Copy link
Contributor

ahcorde commented Oct 6, 2025

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Linux-rhel Build Status
  • Windows Build Status

@ahcorde ahcorde merged commit 8cd98e6 into ros:rolling Oct 7, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants