[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>
This commit is contained in:
Rosen Penev 2020-03-26 21:29:30 -07:00
parent 3540cf26b1
commit 015cbff93d
7 changed files with 12 additions and 36 deletions

View File

@ -127,12 +127,7 @@ gcc_pure
static bool static bool
IsValidValue(const StringView s) noexcept IsValidValue(const StringView s) noexcept
{ {
for (const char ch : s) { return std::none_of(s.begin(), s.end(), [](const auto &ch) { return (unsigned char)ch < 0x20; });
if ((unsigned char)ch < 0x20)
return false;
}
return true;
} }
class PrintCommentHandler final : public NullTagHandler { class PrintCommentHandler final : public NullTagHandler {

View File

@ -33,11 +33,8 @@ InputPlugin::SupportsUri(const char *uri) const noexcept
if (StringStartsWithIgnoreCase(uri, *i)) if (StringStartsWithIgnoreCase(uri, *i))
return true; return true;
} else { } else {
for (const auto& schema : protocols()) { return std::any_of(protocols().begin(), protocols().end(), [uri](const auto &schema)
if (StringStartsWithIgnoreCase(uri, schema.c_str())){ { return StringStartsWithIgnoreCase(uri, schema.c_str()); } );
return true;
}
}
} }
return false; return false;
} }

View File

@ -113,11 +113,7 @@ public:
#ifndef NDEBUG #ifndef NDEBUG
gcc_pure gcc_pure
bool IsEmpty() const noexcept { bool IsEmpty() const noexcept {
for (const auto &c : list) return std::all_of(list.begin(), list.end(), [](const auto &c) { return c.IsCancelled(); });
if (!c.IsCancelled())
return false;
return true;
} }
#endif #endif

View File

@ -258,11 +258,8 @@ MultipleOutputs::Open(const AudioFormat audio_format)
bool bool
MultipleOutputs::IsChunkConsumed(const MusicChunk *chunk) const noexcept MultipleOutputs::IsChunkConsumed(const MusicChunk *chunk) const noexcept
{ {
for (const auto &ao : outputs) return std::all_of(outputs.begin(), outputs.end(), [chunk](const auto &ao) {
if (!ao->LockIsChunkConsumed(*chunk)) return ao->LockIsChunkConsumed(*chunk); });
return false;
return true;
} }
unsigned unsigned

View File

@ -28,6 +28,7 @@
#include "Chrono.hxx" #include "Chrono.hxx"
#include "util/Compiler.h" #include "util/Compiler.h"
#include <algorithm>
#include <cassert> #include <cassert>
#include <memory> #include <memory>
#include <vector> #include <vector>
@ -106,11 +107,7 @@ public:
*/ */
gcc_pure gcc_pure
bool IsDummy() const noexcept { bool IsDummy() const noexcept {
for (const auto &i : outputs) return std::all_of(outputs.begin(), outputs.end(), [](const auto &i) { return i->IsDummy(); });
if (!i->IsDummy())
return false;
return true;
} }
/** /**

View File

@ -19,6 +19,8 @@
#include "AndSongFilter.hxx" #include "AndSongFilter.hxx"
#include <algorithm>
ISongFilterPtr ISongFilterPtr
AndSongFilter::Clone() const noexcept AndSongFilter::Clone() const noexcept
{ {
@ -54,9 +56,5 @@ AndSongFilter::ToExpression() const noexcept
bool bool
AndSongFilter::Match(const LightSong &song) const noexcept AndSongFilter::Match(const LightSong &song) const noexcept
{ {
for (const auto &i : items) return std::all_of(items.begin(), items.end(), [&song](const auto &i) { return i->Match(song); });
if (!i->Match(song))
return false;
return true;
} }

View File

@ -154,11 +154,7 @@ TagBuilder::CommitNew() noexcept
bool bool
TagBuilder::HasType(TagType type) const noexcept TagBuilder::HasType(TagType type) const noexcept
{ {
for (auto i : items) return std::any_of(items.begin(), items.end(), [type](const auto &i) { return i->type == type; });
if (i->type == type)
return true;
return false;
} }
void void