From fbd95516f4a7ffadc2fb1baee5f56c3fcea8229f Mon Sep 17 00:00:00 2001 From: elsid Date: Fri, 11 Feb 2022 21:28:24 +0100 Subject: [PATCH] Repalce raw for-loops by corresponding algorithms --- components/nif/niffile.cpp | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/components/nif/niffile.cpp b/components/nif/niffile.cpp index f3355c4e77..bf604f5adf 100644 --- a/components/nif/niffile.cpp +++ b/components/nif/niffile.cpp @@ -6,6 +6,7 @@ #include #include #include +#include namespace Nif { @@ -181,18 +182,11 @@ void NIFFile::parse(Files::IStreamPtr stream) "NetImmerse File Format", "Gamebryo File Format" }; - bool supported = false; - for (const std::string& verString : verStrings) - { - supported = (head.compare(0, verString.size(), verString) == 0); - if (supported) - break; - } - if (!supported) + const bool supportedHeader = std::any_of(verStrings.begin(), verStrings.end(), + [&] (const std::string& verString) { return head.compare(0, verString.size(), verString) == 0; }); + if (!supportedHeader) fail("Invalid NIF header: " + head); - supported = false; - // Get BCD version ver = nif.getUInt(); // 4.0.0.0 is an older, practically identical version of the format. @@ -202,13 +196,8 @@ void NIFFile::parse(Files::IStreamPtr stream) NIFStream::generateVersion(4,0,0,0), VER_MW }; - for (uint32_t supportedVer : supportedVers) - { - supported = (ver == supportedVer); - if (supported) - break; - } - if (!supported) + const bool supportedVersion = std::find(supportedVers.begin(), supportedVers.end(), ver) != supportedVers.end(); + if (!supportedVersion) { if (sLoadUnsupportedFiles) warn("Unsupported NIF version: " + printVersion(ver) + ". Proceed with caution!"); @@ -311,7 +300,7 @@ void NIFFile::parse(Files::IStreamPtr stream) r = entry->second(); - if (!supported) + if (!supportedVersion) Log(Debug::Verbose) << "NIF Debug: Reading record of type " << rec << ", index " << i << " (" << filename << ")"; assert(r != nullptr);