From 16da43e1f074c9211947da83cbfe240c12337a4b Mon Sep 17 00:00:00 2001 From: Jackie Kay Date: Thu, 17 Dec 2015 11:15:10 -0800 Subject: [PATCH] Avoid reinitializing allocator --- rclcpp/include/rclcpp/intra_process_manager_impl.hpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/rclcpp/include/rclcpp/intra_process_manager_impl.hpp b/rclcpp/include/rclcpp/intra_process_manager_impl.hpp index 89c6f0c..c63e2a7 100644 --- a/rclcpp/include/rclcpp/intra_process_manager_impl.hpp +++ b/rclcpp/include/rclcpp/intra_process_manager_impl.hpp @@ -142,7 +142,7 @@ public: std::lock_guard lock(runtime_mutex_); auto it = publishers_.find(intra_process_publisher_id); if (it == publishers_.end()) { - throw std::runtime_error("store_intra_process_message called with invalid publisher id"); + throw std::runtime_error("get_publisher_info_for_id called with invalid publisher id"); } PublisherInfo & info = it->second; // Calculate the next message sequence number. @@ -168,7 +168,12 @@ public: // Figure out what subscriptions should receive the message. auto & destined_subscriptions = subscription_ids_by_topic_[publisher->get_topic_name()]; // Store the list for later comparison. - info.target_subscriptions_by_message_sequence[message_seq].clear(); + if (info.target_subscriptions_by_message_sequence.count(message_seq) == 0) { + info.target_subscriptions_by_message_sequence.emplace( + message_seq, AllocSet(std::less(), uint64_allocator)); + } else { + info.target_subscriptions_by_message_sequence[message_seq].clear(); + } std::copy( destined_subscriptions.begin(), destined_subscriptions.end(), // Memory allocation occurs in info.target_subscriptions_by_message_sequence[message_seq] @@ -242,6 +247,8 @@ private: template using RebindAlloc = typename std::allocator_traits::template rebind_alloc; + RebindAlloc uint64_allocator; + using AllocSet = std::set, RebindAlloc>; using SubscriptionMap = std::unordered_map, std::equal_to,