From 9bcd425a8587deeb74fb8f186e2cf6ad640b778b Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Sat, 13 Nov 2021 17:27:07 -0800 Subject: [PATCH] array conversions Signed-off-by: Rosen Penev --- src/event/SignalMonitor.cxx | 9 +++++---- src/output/plugins/AlsaOutputPlugin.cxx | 2 +- src/pcm/Dsd2Pcm.cxx | 4 ++-- src/pcm/Dsd2Pcm.hxx | 2 +- src/util/UriUtil.cxx | 5 +++-- 5 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/event/SignalMonitor.cxx b/src/event/SignalMonitor.cxx index 32857081e..f19ca060d 100644 --- a/src/event/SignalMonitor.cxx +++ b/src/event/SignalMonitor.cxx @@ -37,6 +37,7 @@ #endif #include +#include #include #include @@ -90,12 +91,12 @@ private: /* this should be enough - is it? */ static constexpr unsigned MAX_SIGNAL = 64; -static SignalHandler signal_handlers[MAX_SIGNAL]; +static std::array signal_handlers; #ifdef USE_SIGNALFD static sigset_t signal_mask; #else -static std::atomic_bool signal_pending[MAX_SIGNAL]; +static std::array signal_pending; #endif static Manual monitor; @@ -153,7 +154,7 @@ void SignalMonitorFinish() noexcept { #ifdef USE_SIGNALFD - std::fill_n(signal_handlers, MAX_SIGNAL, nullptr); + signal_handlers = {}; #else struct sigaction sa; sa.sa_flags = 0; @@ -167,7 +168,7 @@ SignalMonitorFinish() noexcept } } - std::fill_n(signal_pending, MAX_SIGNAL, false); + std::fill(signal_pending.begin(), signal_pending.end(), false); #endif monitor.Destruct(); diff --git a/src/output/plugins/AlsaOutputPlugin.cxx b/src/output/plugins/AlsaOutputPlugin.cxx index 12f12d531..eebd47540 100644 --- a/src/output/plugins/AlsaOutputPlugin.cxx +++ b/src/output/plugins/AlsaOutputPlugin.cxx @@ -760,7 +760,7 @@ Play_44_1_Silence(snd_pcm_t *pcm) throw Alsa::MakeError(err, "snd_pcm_prepare() failed"); AllocatedArray buffer{channels * period_size}; - std::fill(buffer.begin(), buffer.end(), 0); + buffer = {}; /* play at least 250ms of silence */ for (snd_pcm_uframes_t remaining_frames = rate / 4;;) { diff --git a/src/pcm/Dsd2Pcm.cxx b/src/pcm/Dsd2Pcm.cxx index b9efb3ccf..05bc09e08 100644 --- a/src/pcm/Dsd2Pcm.cxx +++ b/src/pcm/Dsd2Pcm.cxx @@ -172,7 +172,7 @@ void Dsd2Pcm::Reset() noexcept { /* my favorite silence pattern */ - std::fill_n(fifo, std::size(fifo), 0x69); + fifo.fill(0x69); fifopos = 0; /* 0x69 = 01101001 @@ -186,7 +186,7 @@ inline void Dsd2Pcm::ApplySample(size_t ffp, uint8_t src) noexcept { fifo[ffp] = src; - uint8_t *p = fifo + ((ffp-CTABLES) & FIFOMASK); + uint8_t *p = fifo.data() + ((ffp-CTABLES) & FIFOMASK); *p = bit_reverse(*p); } diff --git a/src/pcm/Dsd2Pcm.hxx b/src/pcm/Dsd2Pcm.hxx index 23f79a01b..d3fa9255f 100644 --- a/src/pcm/Dsd2Pcm.hxx +++ b/src/pcm/Dsd2Pcm.hxx @@ -51,7 +51,7 @@ private: /** bit mask for FIFO offsets */ static constexpr size_t FIFOMASK = FIFOSIZE - 1; - uint8_t fifo[FIFOSIZE]; + std::array fifo; size_t fifopos; public: diff --git a/src/util/UriUtil.cxx b/src/util/UriUtil.cxx index 631917ba1..7f675a485 100644 --- a/src/util/UriUtil.cxx +++ b/src/util/UriUtil.cxx @@ -31,6 +31,7 @@ #include "ASCII.hxx" #include "SplitString.hxx" +#include #include #include @@ -73,7 +74,7 @@ gcc_pure static const char * SkipUriScheme(const char *uri) noexcept { - static const char *const schemes[] = { + static constexpr auto schemes = std::array { "http://", "https://", "ftp://", "smb://", @@ -100,7 +101,7 @@ uri_remove_auth(const char *uri) noexcept if (slash == nullptr) slash = auth + strlen(auth); - const char *at = (const char *)std::memchr(auth, '@', slash - auth); + auto at = (const char *)std::memchr(auth, '@', slash - auth); if (at == nullptr) /* no auth info present, do nothing */ return std::string();