From b73b0132bafbc5a836afd2ff5ea956e3506ee716 Mon Sep 17 00:00:00 2001 From: Saeed Maleki Date: Tue, 25 Apr 2023 21:27:23 +0000 Subject: [PATCH] using find instead of searching --- src/bootstrap/bootstrap.cc | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/bootstrap/bootstrap.cc b/src/bootstrap/bootstrap.cc index 2c83d8ea..51ac66d9 100644 --- a/src/bootstrap/bootstrap.cc +++ b/src/bootstrap/bootstrap.cc @@ -4,6 +4,7 @@ #include "mscclpp.hpp" #include "utils.h" +#include #include #include #include @@ -399,14 +400,14 @@ void Bootstrap::Impl::send(void* data, int size, int peer, int tag) void Bootstrap::Impl::recv(void* data, int size, int peer, int tag) { // search over all unexpected messages - for (auto it = unexpectedMessages_.begin(); it != unexpectedMessages_.end(); ++it) { - if (it->peer == peer && it->tag == tag) { - // found a match - netRecv(it->sock.get(), data, size); - MSCCLPPTHROW(mscclppSocketClose(it->sock.get())); - unexpectedMessages_.erase(it); - return; - } + auto lambda = [peer, tag](const UnexpectedMsg& msg) { return msg.peer == peer && msg.tag == tag; }; + auto it = std::find_if(unexpectedMessages_.begin(), unexpectedMessages_.end(), lambda); + if (it != unexpectedMessages_.end()) { + // found a match + netRecv(it->sock.get(), data, size); + MSCCLPPTHROW(mscclppSocketClose(it->sock.get())); + unexpectedMessages_.erase(it); + return; } // didn't find one while (true) {