Merge remote-tracking branches 'neheb/uniq', 'neheb/bool', 'neheb/loop', 'neheb/bool2', 'neheb/perf', 'neheb/void' and 'neheb/value'

This commit is contained in:
Max Kellermann 2020-02-02 16:22:19 +01:00
26 changed files with 49 additions and 51 deletions

View File

@ -107,7 +107,7 @@ static constexpr OptionDef option_defs[] = {
static constexpr Domain cmdline_domain("cmdline"); static constexpr Domain cmdline_domain("cmdline");
gcc_noreturn gcc_noreturn
static void version(void) static void version()
{ {
printf("Music Player Daemon " VERSION " (%s)" printf("Music Player Daemon " VERSION " (%s)"
"\n" "\n"
@ -273,7 +273,7 @@ static void PrintOption(const OptionDef &opt)
} }
gcc_noreturn gcc_noreturn
static void help(void) static void help()
{ {
printf("Usage:\n" printf("Usage:\n"
" mpd [OPTION...] [path/to/mpd.conf]\n" " mpd [OPTION...] [path/to/mpd.conf]\n"
@ -283,7 +283,7 @@ static void help(void)
"Options:\n"); "Options:\n");
for (const auto &i : option_defs) for (const auto &i : option_defs)
if(i.HasDescription() == true) // hide hidden options from help print if(i.HasDescription()) // hide hidden options from help print
PrintOption(i); PrintOption(i);
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);

View File

@ -63,7 +63,7 @@ static void redirect_logs(int fd)
} }
static int static int
open_log_file(void) open_log_file()
{ {
assert(!out_path.IsNull()); assert(!out_path.IsNull());

View File

@ -73,7 +73,7 @@ archive_plugin_from_name(const char *name) noexcept
return nullptr; return nullptr;
} }
void archive_plugin_init_all(void) void archive_plugin_init_all()
{ {
for (unsigned i = 0; archive_plugins[i] != nullptr; ++i) { for (unsigned i = 0; archive_plugins[i] != nullptr; ++i) {
const ArchivePlugin *plugin = archive_plugins[i]; const ArchivePlugin *plugin = archive_plugins[i];

View File

@ -32,6 +32,7 @@
#include <bzlib.h> #include <bzlib.h>
#include <stdexcept> #include <stdexcept>
#include <utility>
class Bzip2ArchiveFile final : public ArchiveFile { class Bzip2ArchiveFile final : public ArchiveFile {
std::string name; std::string name;
@ -65,7 +66,7 @@ class Bzip2InputStream final : public InputStream {
char buffer[5000]; char buffer[5000];
public: public:
Bzip2InputStream(const std::shared_ptr<InputStream> &_input, Bzip2InputStream(std::shared_ptr<InputStream> _input,
const char *uri, const char *uri,
Mutex &mutex); Mutex &mutex);
~Bzip2InputStream() override; ~Bzip2InputStream() override;
@ -111,11 +112,11 @@ bz2_open(Path pathname)
/* single archive handling */ /* single archive handling */
Bzip2InputStream::Bzip2InputStream(const std::shared_ptr<InputStream> &_input, Bzip2InputStream::Bzip2InputStream(std::shared_ptr<InputStream> _input,
const char *_uri, const char *_uri,
Mutex &_mutex) Mutex &_mutex)
:InputStream(_uri, _mutex), :InputStream(_uri, _mutex),
input(_input) input(std::move(_input))
{ {
Open(); Open();
} }

View File

@ -34,6 +34,8 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <utility>
#define CEILING(x, y) ((x+(y-1))/y) #define CEILING(x, y) ((x+(y-1))/y)
struct Iso9660 { struct Iso9660 {
@ -141,12 +143,12 @@ class Iso9660InputStream final : public InputStream {
iso9660_stat_t *statbuf; iso9660_stat_t *statbuf;
public: public:
Iso9660InputStream(const std::shared_ptr<Iso9660> &_iso, Iso9660InputStream(std::shared_ptr<Iso9660> _iso,
const char *_uri, const char *_uri,
Mutex &_mutex, Mutex &_mutex,
iso9660_stat_t *_statbuf) iso9660_stat_t *_statbuf)
:InputStream(_uri, _mutex), :InputStream(_uri, _mutex),
iso(_iso), statbuf(_statbuf) { iso(std::move(_iso)), statbuf(_statbuf) {
size = statbuf->size; size = statbuf->size;
seekable = true; seekable = true;
SetReady(); SetReady();

View File

@ -246,8 +246,8 @@ static CommandResult
PrintAvailableCommands(Response &r, const Partition &partition, PrintAvailableCommands(Response &r, const Partition &partition,
unsigned permission) noexcept unsigned permission) noexcept
{ {
for (unsigned i = 0; i < num_commands; ++i) { for (const auto & i : commands) {
const struct command *cmd = &commands[i]; const struct command *cmd = &i;
if (cmd->permission == (permission & cmd->permission) && if (cmd->permission == (permission & cmd->permission) &&
command_available(partition, cmd)) command_available(partition, cmd))
@ -260,8 +260,8 @@ PrintAvailableCommands(Response &r, const Partition &partition,
static CommandResult static CommandResult
PrintUnavailableCommands(Response &r, unsigned permission) noexcept PrintUnavailableCommands(Response &r, unsigned permission) noexcept
{ {
for (unsigned i = 0; i < num_commands; ++i) { for (const auto & i : commands) {
const struct command *cmd = &commands[i]; const struct command *cmd = &i;
if (cmd->permission != (permission & cmd->permission)) if (cmd->permission != (permission & cmd->permission))
r.Format("command: %s\n", cmd->cmd); r.Format("command: %s\n", cmd->cmd);

View File

@ -23,14 +23,15 @@
#include "song/Filter.hxx" #include "song/Filter.hxx"
#include <algorithm> #include <algorithm>
#include <utility>
#include <assert.h> #include <assert.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
DatabaseVisitorHelper::DatabaseVisitorHelper(const DatabaseSelection &_selection, DatabaseVisitorHelper::DatabaseVisitorHelper(DatabaseSelection _selection,
VisitSong &visit_song) noexcept VisitSong &visit_song) noexcept
:selection(_selection) :selection(std::move(_selection))
{ {
// TODO: apply URI and SongFilter // TODO: apply URI and SongFilter
assert(selection.uri.empty()); assert(selection.uri.empty());

View File

@ -60,7 +60,7 @@ public:
* @param visit_song the callback function passed to * @param visit_song the callback function passed to
* Database::Visit(); may be replaced by this class * Database::Visit(); may be replaced by this class
*/ */
DatabaseVisitorHelper(const DatabaseSelection &selection, DatabaseVisitorHelper(DatabaseSelection selection,
VisitSong &visit_song) noexcept; VisitSong &visit_song) noexcept;
~DatabaseVisitorHelper() noexcept; ~DatabaseVisitorHelper() noexcept;

View File

@ -863,10 +863,7 @@ IsFilterSupported(const ISongFilter &f) noexcept
return true; return true;
const auto tag = Convert(t->GetTagType()); const auto tag = Convert(t->GetTagType());
if (tag == MPD_TAG_COUNT) return tag != MPD_TAG_COUNT;
return false;
return true;
} else if (auto u = dynamic_cast<const UriSongFilter *>(&f)) { } else if (auto u = dynamic_cast<const UriSongFilter *>(&f)) {
if (u->IsNegated()) if (u->IsNegated())
// TODO implement // TODO implement

View File

@ -330,7 +330,7 @@ mpd_inotify_init(EventLoop &loop, Storage &storage, UpdateService &update,
} }
void void
mpd_inotify_finish(void) noexcept mpd_inotify_finish() noexcept
{ {
if (inotify_source == nullptr) if (inotify_source == nullptr)
return; return;

View File

@ -102,7 +102,7 @@ flac_scan_stream(InputStream &is, TagHandler &handler) noexcept
* Some glue code around FLAC__stream_decoder_new(). * Some glue code around FLAC__stream_decoder_new().
*/ */
static FlacStreamDecoder static FlacStreamDecoder
flac_decoder_new(void) flac_decoder_new()
{ {
FlacStreamDecoder sd; FlacStreamDecoder sd;
if(!FLAC__stream_decoder_set_metadata_respond(sd.get(), FLAC__METADATA_TYPE_VORBIS_COMMENT)) if(!FLAC__stream_decoder_set_metadata_respond(sd.get(), FLAC__METADATA_TYPE_VORBIS_COMMENT))

View File

@ -516,8 +516,8 @@ parse_xing(struct xing *xing, struct mad_bitptr *ptr, int *oldbitlen) noexcept
if (xing->flags & XING_TOC) { if (xing->flags & XING_TOC) {
if (bitlen < 800) if (bitlen < 800)
return false; return false;
for (unsigned i = 0; i < 100; ++i) for (unsigned char & i : xing->toc)
xing->toc[i] = mad_bit_read(ptr, 8); i = mad_bit_read(ptr, 8);
bitlen -= 800; bitlen -= 800;
} }

View File

@ -38,24 +38,24 @@ static constexpr Domain mikmod_domain("mikmod");
static constexpr size_t MIKMOD_FRAME_SIZE = 4096; static constexpr size_t MIKMOD_FRAME_SIZE = 4096;
static BOOL static BOOL
mikmod_mpd_init(void) mikmod_mpd_init()
{ {
return VC_Init(); return VC_Init();
} }
static void static void
mikmod_mpd_exit(void) mikmod_mpd_exit()
{ {
VC_Exit(); VC_Exit();
} }
static void static void
mikmod_mpd_update(void) mikmod_mpd_update()
{ {
} }
static BOOL static BOOL
mikmod_mpd_is_present(void) mikmod_mpd_is_present()
{ {
return true; return true;
} }

View File

@ -102,10 +102,7 @@ FullyBufferedSocket::OnSocketReady(unsigned flags) noexcept
return false; return false;
} }
if (!BufferedSocket::OnSocketReady(flags)) return BufferedSocket::OnSocketReady(flags);
return false;
return true;
} }
void void

View File

@ -33,7 +33,7 @@ InputPlugin::SupportsUri(const char *uri) const noexcept
if (StringStartsWithIgnoreCase(uri, *i)) if (StringStartsWithIgnoreCase(uri, *i))
return true; return true;
} else { } else {
for (auto schema : protocols()) { for (const auto& schema : protocols()) {
if (StringStartsWithIgnoreCase(uri, schema.c_str())){ if (StringStartsWithIgnoreCase(uri, schema.c_str())){
return true; return true;
} }

View File

@ -162,7 +162,7 @@ parse_cdio_uri(const char *src)
} }
static AllocatedPath static AllocatedPath
cdio_detect_device(void) cdio_detect_device()
{ {
char **devices = cdio_get_devices_with_cap(nullptr, CDIO_FS_AUDIO, char **devices = cdio_get_devices_with_cap(nullptr, CDIO_FS_AUDIO,
false); false);

View File

@ -39,7 +39,7 @@ void print_supported_uri_schemes_to_fp(FILE *fp)
protocols.emplace(uri); protocols.emplace(uri);
}); });
for (auto protocol : protocols) { for (const auto& protocol : protocols) {
fprintf(fp, " %s", protocol.c_str()); fprintf(fp, " %s", protocol.c_str());
} }
fprintf(fp,"\n"); fprintf(fp,"\n");
@ -54,7 +54,7 @@ print_supported_uri_schemes(Response &r)
protocols.emplace(uri); protocols.emplace(uri);
}); });
for (auto protocol : protocols) { for (const auto& protocol : protocols) {
r.Format("handler: %s\n", protocol.c_str()); r.Format("handler: %s\n", protocol.c_str());
} }
} }

View File

@ -84,8 +84,8 @@ NeighborGlue::Open()
void void
NeighborGlue::Close() noexcept NeighborGlue::Close() noexcept
{ {
for (auto i = explorers.begin(), end = explorers.end(); i != end; ++i) for (auto & explorer : explorers)
i->explorer->Close(); explorer.explorer->Close();
} }
NeighborGlue::List NeighborGlue::List

View File

@ -80,7 +80,7 @@ audio_output_state_read(const char *line, MultipleOutputs &outputs)
} }
unsigned unsigned
audio_output_state_get_version(void) audio_output_state_get_version()
{ {
return audio_output_state_version; return audio_output_state_version;
} }

View File

@ -419,7 +419,7 @@ JackOutput::Connect()
} }
static bool static bool
mpd_jack_test_default_device(void) mpd_jack_test_default_device()
{ {
return true; return true;
} }

View File

@ -872,7 +872,7 @@ try {
} }
static bool static bool
pulse_output_test_default_device(void) pulse_output_test_default_device()
{ {
return PulseOutput::TestDefaultDevice(); return PulseOutput::TestDefaultDevice();
} }

View File

@ -44,7 +44,7 @@ mixramp_interpolate(const char *ramp_list, float required_db) noexcept
* between the dB and seconds of a pair. * between the dB and seconds of a pair.
* The dB values must be monotonically increasing for this to work. */ * The dB values must be monotonically increasing for this to work. */
while (1) { while (true) {
/* Parse the dB value. */ /* Parse the dB value. */
char *endptr; char *endptr;
const float db = ParseFloat(ramp_list, &endptr); const float db = ParseFloat(ramp_list, &endptr);

View File

@ -1155,7 +1155,7 @@ try {
std::unique_lock<Mutex> lock(mutex); std::unique_lock<Mutex> lock(mutex);
while (1) { while (true) {
switch (command) { switch (command) {
case PlayerCommand::SEEK: case PlayerCommand::SEEK:
case PlayerCommand::QUEUE: case PlayerCommand::QUEUE:

View File

@ -177,11 +177,11 @@ SoundCloudJsonData::EndMap() noexcept
{ {
if (got_url > 1) { if (got_url > 1) {
got_url--; got_url--;
return 1; return true;
} }
if (got_url == 0) if (got_url == 0)
return 1; return true;
/* got_url == 1, track finished, make it into a song */ /* got_url == 1, track finished, make it into a song */
got_url = 0; got_url = 0;

View File

@ -139,7 +139,7 @@ storage_state_get_hash(const Instance &instance)
boost::crc_32_type result; boost::crc_32_type result;
for (auto mount: mounts) { for (const auto& mount : mounts) {
result.process_bytes(mount.c_str(), mount.length()); result.process_bytes(mount.c_str(), mount.length());
} }

View File

@ -66,7 +66,7 @@ static bool had_group = false;
static int detach_fd = -1; static int detach_fd = -1;
void void
daemonize_kill(void) daemonize_kill()
{ {
if (pidfile.IsNull()) if (pidfile.IsNull())
throw std::runtime_error("no pid_file specified in the config file"); throw std::runtime_error("no pid_file specified in the config file");
@ -85,14 +85,14 @@ daemonize_kill(void)
} }
void void
daemonize_close_stdin(void) daemonize_close_stdin()
{ {
close(STDIN_FILENO); close(STDIN_FILENO);
open("/dev/null", O_RDONLY); open("/dev/null", O_RDONLY);
} }
void void
daemonize_set_user(void) daemonize_set_user()
{ {
if (user_name == nullptr) if (user_name == nullptr)
return; return;
@ -245,7 +245,7 @@ daemonize_init(const char *user, const char *group, AllocatedPath &&_pidfile)
} }
void void
daemonize_finish(void) daemonize_finish()
{ {
if (!pidfile.IsNull()) { if (!pidfile.IsNull()) {
unlink(pidfile.c_str()); unlink(pidfile.c_str());