Skip to content

Commit

Permalink
use std::find_if to find matching pubs
Browse files Browse the repository at this point in the history
Signed-off-by: Yadunund <[email protected]>
  • Loading branch information
Yadunund committed Nov 23, 2023
1 parent 8569898 commit adc0a2f
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions rmw_zenoh_cpp/src/detail/graph_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include <algorithm>
#include <memory>
#include <mutex>
#include <optional>
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit adc0a2f

Please sign in to comment.