From adc0a2f9c424200abf689e1ba93b1264ff786d8a Mon Sep 17 00:00:00 2001 From: Yadunund Date: Thu, 23 Nov 2023 14:01:35 +0800 Subject: [PATCH] use std::find_if to find matching pubs Signed-off-by: Yadunund --- rmw_zenoh_cpp/src/detail/graph_cache.cpp | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/rmw_zenoh_cpp/src/detail/graph_cache.cpp b/rmw_zenoh_cpp/src/detail/graph_cache.cpp index 025b0047..8107a373 100644 --- a/rmw_zenoh_cpp/src/detail/graph_cache.cpp +++ b/rmw_zenoh_cpp/src/detail/graph_cache.cpp @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include #include #include #include @@ -425,16 +426,13 @@ void GraphCache::parse_del(const std::string & keyexpr) // Here we iterate throught the list of publishers and remove the one // with matching name, type and qos. // TODO(Yadunund): This can be more optimal than O(n) with some caching. - auto erase_it = found_node->pubs.begin(); - for (; erase_it != found_node->pubs.end(); ++erase_it) { - const auto & pub = *erase_it; - if (pub.topic == node->pubs.at(0).topic && + auto erase_it = std::find_if( + found_node->pubs.begin(), found_node->pubs.end(), + [&node](const auto & pub) { + return pub.topic == node->pubs.at(0).topic && pub.type == node->pubs.at(0).type && - pub.qos == node->pubs.at(0).qos) - { - break; - } - } + pub.qos == node->pubs.at(0).qos; + }); if (erase_it != found_node->pubs.end()) { found_node->pubs.erase(erase_it); // Bookkeeping