Commit 015cbff9 authored by Rosen Penev's avatar Rosen Penev

[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: 's avatarRosen Penev <rosenp@gmail.com>
parent 3540cf26
......@@ -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 {
......
......@@ -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;
}
......
......@@ -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
......
......@@ -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
......
......@@ -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(); });
}
/**
......
......@@ -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); });
}
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment