manager: fixup to use find_if
[manager.cpp:150]: (style) Consider using std::find_if algorithm
instead of a raw loop.
Note: Amusingly switching to a const iterator allowed cppcheck to find
this cleanup.
Change-Id: I16d87d4dde165fbb226259d1abc8deaa51569af1
Signed-off-by: Patrick Venture <venture@google.com>
diff --git a/manager.cpp b/manager.cpp
index 0a30625..adabe84 100644
--- a/manager.cpp
+++ b/manager.cpp
@@ -14,6 +14,7 @@
* limitations under the License.
*/
+#include <algorithm>
#include <blobs-ipmid/manager.hpp>
#include <memory>
#include <string>
@@ -142,18 +143,15 @@
GenericBlobInterface* BlobManager::getHandler(const std::string& path)
{
/* Find a handler. */
- GenericBlobInterface* handler = nullptr;
-
- for (const auto& h : handlers)
+ auto h = std::find_if(
+ handlers.begin(), handlers.end(),
+ [&path](const auto& iter) { return (iter->canHandleBlob(path)); });
+ if (h != handlers.end())
{
- if (h->canHandleBlob(path))
- {
- handler = h.get();
- break;
- }
+ return h->get();
}
- return handler;
+ return nullptr;
}
GenericBlobInterface* BlobManager::getHandler(uint16_t session)