From 4b1de12fe7648eaee6d4694f76d6bc2d2b99b048 Mon Sep 17 00:00:00 2001 From: Sai Kishor Kothakota Date: Tue, 13 Aug 2024 10:53:32 +0200 Subject: [PATCH] Improve string concatenation for real-time --- controller_manager/src/controller_manager.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/controller_manager/src/controller_manager.cpp b/controller_manager/src/controller_manager.cpp index bf06e40476..13ecd593f2 100644 --- a/controller_manager/src/controller_manager.cpp +++ b/controller_manager/src/controller_manager.cpp @@ -2140,17 +2140,21 @@ void ControllerManager::read(const rclcpp::Time & time, const rclcpp::Duration & { std::vector stop_request = {}; std::string failed_hardware_string; + failed_hardware_string.reserve(500); // Determine controllers to stop for (const auto & hardware_name : failed_hardware_names) { - failed_hardware_string += hardware_name + " "; + failed_hardware_string.append(hardware_name); + failed_hardware_string.append(" "); auto controllers = resource_manager_->get_cached_controllers_to_hardware(hardware_name); stop_request.insert(stop_request.end(), controllers.begin(), controllers.end()); } std::string stop_request_string; + stop_request_string.reserve(500); for (const auto & controller : stop_request) { - stop_request_string += controller + " "; + stop_request_string.append(controller); + stop_request_string.append(" "); } RCLCPP_ERROR( get_logger(), @@ -2310,17 +2314,21 @@ void ControllerManager::write(const rclcpp::Time & time, const rclcpp::Duration { std::vector stop_request = {}; std::string failed_hardware_string; + failed_hardware_string.reserve(500); // Determine controllers to stop for (const auto & hardware_name : failed_hardware_names) { - failed_hardware_string += hardware_name + " "; + failed_hardware_string.append(hardware_name); + failed_hardware_string.append(" "); auto controllers = resource_manager_->get_cached_controllers_to_hardware(hardware_name); stop_request.insert(stop_request.end(), controllers.begin(), controllers.end()); } std::string stop_request_string; + stop_request_string.reserve(500); for (const auto & controller : stop_request) { - stop_request_string += controller + " "; + stop_request_string.append(controller); + stop_request_string.append(" "); } RCLCPP_ERROR( get_logger(),