From 567467e91adf08f19a1ae71d4ec573e46ccf63bf Mon Sep 17 00:00:00 2001 From: Uwe Seimet Date: Fri, 8 Sep 2023 19:24:33 +0200 Subject: [PATCH] Optimize using find_if_not() --- cpp/piscsi/piscsi_executor.cpp | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/cpp/piscsi/piscsi_executor.cpp b/cpp/piscsi/piscsi_executor.cpp index d178894c36..652fffc32d 100644 --- a/cpp/piscsi/piscsi_executor.cpp +++ b/cpp/piscsi/piscsi_executor.cpp @@ -625,13 +625,8 @@ string PiscsiExecutor::ValidateLunSetup(const PbCommand& command) const } // LUN 0 must exist for all devices - for (const auto& [id, lun]: luns) { - if (!(lun & 0x01)) { - return "LUN 0 is missing for device ID " + to_string(id); - } - } - - return ""; + const auto& it = ranges::find_if_not(luns, [] (const auto& l) { return l.second & 0x01; } ); + return it == luns.end() ? "" : "LUN 0 is missing for device ID " + to_string((*it).first); } bool PiscsiExecutor::VerifyExistingIdAndLun(const CommandContext& context, int id, int lun) const