diff options
author | Rosen Penev <rosenp@gmail.com> | 2020-03-26 21:29:30 -0700 |
---|---|---|
committer | Rosen Penev <rosenp@gmail.com> | 2020-04-08 14:01:12 -0700 |
commit | 015cbff93dafb17f748a20c806f4a73084a4635e (patch) | |
tree | 397288038526bf9d835ba92b00604ab51f9eb89b | |
parent | 3540cf26b1b342f175255f2dc02e615483a1383c (diff) |
[cppcheck] convert several functions to use std::all_of
std::all_of becomes constexpr in C++20. I'm not sure it results in better
performance.
Found with useStlAlgorithm
Signed-off-by: Rosen Penev <rosenp@gmail.com>
-rw-r--r-- | src/command/FileCommands.cxx | 7 | ||||
-rw-r--r-- | src/input/InputPlugin.cxx | 7 | ||||
-rw-r--r-- | src/lib/nfs/Cancellable.hxx | 6 | ||||
-rw-r--r-- | src/output/MultipleOutputs.cxx | 7 | ||||
-rw-r--r-- | src/output/MultipleOutputs.hxx | 7 | ||||
-rw-r--r-- | src/song/AndSongFilter.cxx | 8 | ||||
-rw-r--r-- | src/tag/Builder.cxx | 6 |
7 files changed, 12 insertions, 36 deletions
diff --git a/src/command/FileCommands.cxx b/src/command/FileCommands.cxx index d8be0da4a..ebe229ebd 100644 --- a/src/command/FileCommands.cxx +++ b/src/command/FileCommands.cxx @@ -127,12 +127,7 @@ gcc_pure static bool IsValidValue(const StringView s) noexcept { - for (const char ch : s) { - if ((unsigned char)ch < 0x20) - return false; - } - - return true; + return std::none_of(s.begin(), s.end(), [](const auto &ch) { return (unsigned char)ch < 0x20; }); } class PrintCommentHandler final : public NullTagHandler { diff --git a/src/input/InputPlugin.cxx b/src/input/InputPlugin.cxx index b682bccaa..f66af0f48 100644 --- a/src/input/InputPlugin.cxx +++ b/src/input/InputPlugin.cxx @@ -33,11 +33,8 @@ InputPlugin::SupportsUri(const char *uri) const noexcept if (StringStartsWithIgnoreCase(uri, *i)) return true; } else { - for (const auto& schema : protocols()) { - if (StringStartsWithIgnoreCase(uri, schema.c_str())){ - return true; - } - } + return std::any_of(protocols().begin(), protocols().end(), [uri](const auto &schema) + { return StringStartsWithIgnoreCase(uri, schema.c_str()); } ); } return false; } diff --git a/src/lib/nfs/Cancellable.hxx b/src/lib/nfs/Cancellable.hxx index a571ac315..9c89ca169 100644 --- a/src/lib/nfs/Cancellable.hxx +++ b/src/lib/nfs/Cancellable.hxx @@ -113,11 +113,7 @@ public: #ifndef NDEBUG gcc_pure bool IsEmpty() const noexcept { - for (const auto &c : list) - if (!c.IsCancelled()) - return false; - - return true; + return std::all_of(list.begin(), list.end(), [](const auto &c) { return c.IsCancelled(); }); } #endif diff --git a/src/output/MultipleOutputs.cxx b/src/output/MultipleOutputs.cxx index f78b8808d..71014e8d1 100644 --- a/src/output/MultipleOutputs.cxx +++ b/src/output/MultipleOutputs.cxx @@ -258,11 +258,8 @@ MultipleOutputs::Open(const AudioFormat audio_format) bool MultipleOutputs::IsChunkConsumed(const MusicChunk *chunk) const noexcept { - for (const auto &ao : outputs) - if (!ao->LockIsChunkConsumed(*chunk)) - return false; - - return true; + return std::all_of(outputs.begin(), outputs.end(), [chunk](const auto &ao) { + return ao->LockIsChunkConsumed(*chunk); }); } unsigned diff --git a/src/output/MultipleOutputs.hxx b/src/output/MultipleOutputs.hxx index 18872ba3e..9c885cb3a 100644 --- a/src/output/MultipleOutputs.hxx +++ b/src/output/MultipleOutputs.hxx @@ -28,6 +28,7 @@ #include "Chrono.hxx" #include "util/Compiler.h" +#include <algorithm> #include <cassert> #include <memory> #include <vector> @@ -106,11 +107,7 @@ public: */ gcc_pure bool IsDummy() const noexcept { - for (const auto &i : outputs) - if (!i->IsDummy()) - return false; - - return true; + return std::all_of(outputs.begin(), outputs.end(), [](const auto &i) { return i->IsDummy(); }); } /** diff --git a/src/song/AndSongFilter.cxx b/src/song/AndSongFilter.cxx index 49db320e3..0a135d222 100644 --- a/src/song/AndSongFilter.cxx +++ b/src/song/AndSongFilter.cxx @@ -19,6 +19,8 @@ #include "AndSongFilter.hxx" +#include <algorithm> + ISongFilterPtr AndSongFilter::Clone() const noexcept { @@ -54,9 +56,5 @@ AndSongFilter::ToExpression() const noexcept bool AndSongFilter::Match(const LightSong &song) const noexcept { - for (const auto &i : items) - if (!i->Match(song)) - return false; - - return true; + return std::all_of(items.begin(), items.end(), [&song](const auto &i) { return i->Match(song); }); } diff --git a/src/tag/Builder.cxx b/src/tag/Builder.cxx index b55f02709..6d6ec8832 100644 --- a/src/tag/Builder.cxx +++ b/src/tag/Builder.cxx @@ -154,11 +154,7 @@ TagBuilder::CommitNew() noexcept bool TagBuilder::HasType(TagType type) const noexcept { - for (auto i : items) - if (i->type == type) - return true; - - return false; + return std::any_of(items.begin(), items.end(), [type](const auto &i) { return i->type == type; }); } void |