From 40c6a214e3b363b5214e660258e3456babfaefa0 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Fri, 20 Aug 2021 23:03:22 -0700 Subject: [PATCH 1/5] unique_ptr/new to make_unique The latter is easier to read and is the "correct" thing to do. Signed-off-by: Rosen Penev --- src/filter/plugins/ConvertFilterPlugin.cxx | 2 +- src/tag/Builder.cxx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/filter/plugins/ConvertFilterPlugin.cxx b/src/filter/plugins/ConvertFilterPlugin.cxx index 5b7c96c74..5dcca8f99 100644 --- a/src/filter/plugins/ConvertFilterPlugin.cxx +++ b/src/filter/plugins/ConvertFilterPlugin.cxx @@ -121,7 +121,7 @@ std::unique_ptr convert_filter_new(const AudioFormat in_audio_format, const AudioFormat out_audio_format) { - std::unique_ptr filter(new ConvertFilter(in_audio_format)); + auto filter = std::make_unique(in_audio_format); filter->Set(out_audio_format); return filter; } diff --git a/src/tag/Builder.cxx b/src/tag/Builder.cxx index b2887c903..3dbb5a383 100644 --- a/src/tag/Builder.cxx +++ b/src/tag/Builder.cxx @@ -158,7 +158,7 @@ TagBuilder::Commit() noexcept std::unique_ptr TagBuilder::CommitNew() noexcept { - std::unique_ptr tag(new Tag()); + auto tag = std::make_unique(); Commit(*tag); return tag; } From 0f7a0b04cabefd329f3932b208a24f584afa60b6 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Fri, 20 Aug 2021 16:08:58 -0700 Subject: [PATCH 2/5] replace loop with find_if loop is wrong anyway. It's missing a break; Signed-off-by: Rosen Penev --- src/db/plugins/upnp/ContentDirectoryService.cxx | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/db/plugins/upnp/ContentDirectoryService.cxx b/src/db/plugins/upnp/ContentDirectoryService.cxx index 720940521..6ab1441b2 100644 --- a/src/db/plugins/upnp/ContentDirectoryService.cxx +++ b/src/db/plugins/upnp/ContentDirectoryService.cxx @@ -258,12 +258,8 @@ ContentDirectoryService::getMetadata(UpnpClient_Handle hdl, if (code != UPNP_E_SUCCESS) throw FormatRuntimeError("UpnpSendAction() failed: %s", UpnpGetErrorMessage(code)); - const char *p = ""; - for (const auto &entry : responseData) { - if (entry.first == "Result") { - p = entry.second.c_str(); - } - } + auto it = std::find_if(responseData.begin(), responseData.end(), [](auto&& entry){ return entry.first == "Result"; }); + const char *p = it != responseData.end() ? it->second.c_str() : ""; UPnPDirContent dirbuf; dirbuf.Parse(p); return dirbuf; From 20d74bb07e542e4a49e845dfff5bc6e6a6167377 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Tue, 17 Aug 2021 20:13:40 -0700 Subject: [PATCH 3/5] clang-tidy: replace loop with std::all_of Found with readability-use-anyofallof Signed-off-by: Rosen Penev --- src/output/plugins/snapcast/SnapcastOutputPlugin.cxx | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/output/plugins/snapcast/SnapcastOutputPlugin.cxx b/src/output/plugins/snapcast/SnapcastOutputPlugin.cxx index 239806122..b6fd6f844 100644 --- a/src/output/plugins/snapcast/SnapcastOutputPlugin.cxx +++ b/src/output/plugins/snapcast/SnapcastOutputPlugin.cxx @@ -367,11 +367,7 @@ SnapcastOutput::IsDrained() const noexcept if (!chunks.empty()) return false; - for (const auto &client : clients) - if (!client.IsDrained()) - return false; - - return true; + return std::all_of(clients.begin(), clients.end(), [](auto&& c){ return c.IsDrained(); }); } void From da1783cdffd07fda4d1d7906b5f57bc2b4628b37 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Tue, 17 Aug 2021 20:16:58 -0700 Subject: [PATCH 4/5] clang-tidy: remove pointless const Found with readability-const-return-type Signed-off-by: Rosen Penev --- src/playlist/cue/CueParser.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/playlist/cue/CueParser.cxx b/src/playlist/cue/CueParser.cxx index 84a98e73d..cb7d2ee19 100644 --- a/src/playlist/cue/CueParser.cxx +++ b/src/playlist/cue/CueParser.cxx @@ -63,7 +63,7 @@ cue_next_token(StringView &src) noexcept return cue_next_word(src); } -static const StringView +static StringView cue_next_value(StringView &src) noexcept { src.StripLeft(); From 1d7a8f992f68fa4081a0c7e84ac18f8ae842fdda Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Tue, 17 Aug 2021 20:00:02 -0700 Subject: [PATCH 5/5] clang-tidy: use auto The type is duplicated otherwise Found with modernize-use-auto Signed-off-by: Rosen Penev --- src/lib/ffmpeg/Interleave.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/ffmpeg/Interleave.cxx b/src/lib/ffmpeg/Interleave.cxx index 51378b53b..4e901315f 100644 --- a/src/lib/ffmpeg/Interleave.cxx +++ b/src/lib/ffmpeg/Interleave.cxx @@ -37,7 +37,7 @@ InterleaveFrame(const AVFrame &frame, FfmpegBuffer &buffer) { assert(frame.nb_samples > 0); - const AVSampleFormat format = AVSampleFormat(frame.format); + const auto format = AVSampleFormat(frame.format); const unsigned channels = frame.channels; const std::size_t n_frames = frame.nb_samples;