*: add "noexcept" to many, many function prototypes

This eliminates some overhead, because the compiler doesn't need to
consider these functions throwing.
This commit is contained in:
Max Kellermann
2017-05-08 14:44:49 +02:00
parent ac2e4e593d
commit 71f0ed8b74
272 changed files with 873 additions and 846 deletions

View File

@@ -54,7 +54,7 @@ DecoderBridge::~DecoderBridge()
}
bool
DecoderBridge::CheckCancelRead() const
DecoderBridge::CheckCancelRead() const noexcept
{
if (error)
/* this translates to DecoderCommand::STOP */
@@ -78,7 +78,7 @@ DecoderBridge::CheckCancelRead() const
* one.
*/
static DecoderCommand
need_chunks(DecoderControl &dc)
need_chunks(DecoderControl &dc) noexcept
{
if (dc.command == DecoderCommand::NONE)
dc.Wait();
@@ -87,14 +87,14 @@ need_chunks(DecoderControl &dc)
}
static DecoderCommand
LockNeedChunks(DecoderControl &dc)
LockNeedChunks(DecoderControl &dc) noexcept
{
const std::lock_guard<Mutex> protect(dc.mutex);
return need_chunks(dc);
}
MusicChunk *
DecoderBridge::GetChunk()
DecoderBridge::GetChunk() noexcept
{
DecoderCommand cmd;
@@ -177,7 +177,7 @@ DecoderBridge::PrepareInitialSeek()
}
DecoderCommand
DecoderBridge::GetVirtualCommand()
DecoderBridge::GetVirtualCommand() noexcept
{
if (error)
/* an error has occurred: stop the decoder plugin */
@@ -192,7 +192,7 @@ DecoderBridge::GetVirtualCommand()
}
DecoderCommand
DecoderBridge::LockGetVirtualCommand()
DecoderBridge::LockGetVirtualCommand() noexcept
{
const std::lock_guard<Mutex> protect(dc.mutex);
return GetVirtualCommand();

View File

@@ -114,7 +114,7 @@ public:
* Caller must lock the #DecoderControl object.
*/
gcc_pure
bool CheckCancelRead() const;
bool CheckCancelRead() const noexcept;
/**
* Returns the current chunk the decoder writes to, or allocates a new
@@ -122,7 +122,7 @@ public:
*
* @return the chunk, or NULL if we have received a decoder command
*/
MusicChunk *GetChunk();
MusicChunk *GetChunk() noexcept;
/**
* Flushes the current chunk.
@@ -161,8 +161,8 @@ private:
* "virtual" synthesized command, e.g. to seek to the
* beginning of the CUE track.
*/
DecoderCommand GetVirtualCommand();
DecoderCommand LockGetVirtualCommand();
DecoderCommand GetVirtualCommand() noexcept;
DecoderCommand LockGetVirtualCommand() noexcept;
/**
* Sends a #Tag as-is to the #MusicPipe. Flushes the current

View File

@@ -74,7 +74,7 @@ DecoderControl::SetReady(const AudioFormat audio_format,
}
bool
DecoderControl::IsCurrentSong(const DetachedSong &_song) const
DecoderControl::IsCurrentSong(const DetachedSong &_song) const noexcept
{
switch (state) {
case DecoderState::STOP:

View File

@@ -305,10 +305,10 @@ struct DecoderControl {
* Caller must lock the object.
*/
gcc_pure
bool IsCurrentSong(const DetachedSong &_song) const;
bool IsCurrentSong(const DetachedSong &_song) const noexcept;
gcc_pure
bool LockIsCurrentSong(const DetachedSong &_song) const {
bool LockIsCurrentSong(const DetachedSong &_song) const noexcept {
const std::lock_guard<Mutex> protect(mutex);
return IsCurrentSong(_song);
}

View File

@@ -118,7 +118,7 @@ static constexpr unsigned num_decoder_plugins =
bool decoder_plugins_enabled[num_decoder_plugins];
const struct DecoderPlugin *
decoder_plugin_from_name(const char *name)
decoder_plugin_from_name(const char *name) noexcept
{
return decoder_plugins_find([=](const DecoderPlugin &plugin){
return strcmp(plugin.name, name) == 0;
@@ -154,7 +154,7 @@ void decoder_plugin_deinit_all(void)
}
bool
decoder_plugins_supports_suffix(const char *suffix)
decoder_plugins_supports_suffix(const char *suffix) noexcept
{
return decoder_plugins_try([suffix](const DecoderPlugin &plugin){
return plugin.SupportsSuffix(suffix);

View File

@@ -31,7 +31,7 @@ extern bool decoder_plugins_enabled[];
gcc_pure
const struct DecoderPlugin *
decoder_plugin_from_name(const char *name);
decoder_plugin_from_name(const char *name) noexcept;
/* this is where we "load" all the "plugins" ;-) */
void
@@ -86,6 +86,6 @@ decoder_plugins_for_each_enabled(F f)
*/
gcc_pure gcc_nonnull_all
bool
decoder_plugins_supports_suffix(const char *suffix);
decoder_plugins_supports_suffix(const char *suffix) noexcept;
#endif

View File

@@ -24,7 +24,7 @@
#include <assert.h>
bool
DecoderPlugin::SupportsSuffix(const char *suffix) const
DecoderPlugin::SupportsSuffix(const char *suffix) const noexcept
{
#if !CLANG_CHECK_VERSION(3,6)
/* disabled on clang due to -Wtautological-pointer-compare */
@@ -36,7 +36,7 @@ DecoderPlugin::SupportsSuffix(const char *suffix) const
}
bool
DecoderPlugin::SupportsMimeType(const char *mime_type) const
DecoderPlugin::SupportsMimeType(const char *mime_type) const noexcept
{
#if !CLANG_CHECK_VERSION(3,6)
/* disabled on clang due to -Wtautological-pointer-compare */

View File

@@ -168,13 +168,13 @@ struct DecoderPlugin {
* Does the plugin announce the specified file name suffix?
*/
gcc_pure gcc_nonnull_all
bool SupportsSuffix(const char *suffix) const;
bool SupportsSuffix(const char *suffix) const noexcept;
/**
* Does the plugin announce the specified MIME type?
*/
gcc_pure gcc_nonnull_all
bool SupportsMimeType(const char *mime_type) const;
bool SupportsMimeType(const char *mime_type) const noexcept;
};
#endif

View File

@@ -170,7 +170,8 @@ decoder_file_decode(const DecoderPlugin &plugin,
gcc_pure
static bool
decoder_check_plugin_mime(const DecoderPlugin &plugin, const InputStream &is)
decoder_check_plugin_mime(const DecoderPlugin &plugin,
const InputStream &is) noexcept
{
assert(plugin.stream_decode != nullptr);
@@ -181,7 +182,8 @@ decoder_check_plugin_mime(const DecoderPlugin &plugin, const InputStream &is)
gcc_pure
static bool
decoder_check_plugin_suffix(const DecoderPlugin &plugin, const char *suffix)
decoder_check_plugin_suffix(const DecoderPlugin &plugin,
const char *suffix) noexcept
{
assert(plugin.stream_decode != nullptr);
@@ -191,7 +193,7 @@ decoder_check_plugin_suffix(const DecoderPlugin &plugin, const char *suffix)
gcc_pure
static bool
decoder_check_plugin(const DecoderPlugin &plugin, const InputStream &is,
const char *suffix)
const char *suffix) noexcept
{
return plugin.stream_decode != nullptr &&
(decoder_check_plugin_mime(plugin, is) ||

View File

@@ -66,7 +66,7 @@ struct AudioFileInputStream {
gcc_pure
static SongTime
audiofile_get_duration(AFfilehandle fh)
audiofile_get_duration(AFfilehandle fh) noexcept
{
return SongTime::FromScale<uint64_t>(afGetFrameCount(fh, AF_DEFAULT_TRACK),
afGetRate(fh, AF_DEFAULT_TRACK));
@@ -239,7 +239,7 @@ audiofile_stream_decode(DecoderClient &client, InputStream &is)
gcc_pure
static SignedSongTime
audiofile_get_duration(InputStream &is)
audiofile_get_duration(InputStream &is) noexcept
{
if (!is.IsSeekable() || !is.KnownSize())
return SignedSongTime::Negative();

View File

@@ -39,7 +39,7 @@
#include <stdlib.h>
bool
DsdId::Equals(const char *s) const
DsdId::Equals(const char *s) const noexcept
{
assert(s != nullptr);
assert(strlen(s) == sizeof(value));
@@ -95,7 +95,7 @@ dsdlib_skip(DecoderClient *client, InputStream &is,
}
bool
dsdlib_valid_freq(uint32_t samplefreq)
dsdlib_valid_freq(uint32_t samplefreq) noexcept
{
switch (samplefreq) {
case 2822400: /* DSD64, 64xFs, Fs = 44.100kHz */

View File

@@ -34,7 +34,7 @@ struct DsdId {
char value[4];
gcc_pure
bool Equals(const char *s) const;
bool Equals(const char *s) const noexcept;
};
class DsdUint64 {
@@ -72,7 +72,7 @@ dsdlib_skip(DecoderClient *client, InputStream &is,
**/
gcc_const
bool
dsdlib_valid_freq(uint32_t samplefreq);
dsdlib_valid_freq(uint32_t samplefreq) noexcept;
/**
* Add tags from ID3 tag. All tags commonly found in the ID3 tags of

View File

@@ -112,14 +112,14 @@ ffmpeg_finish()
gcc_pure
static const AVCodecParameters &
GetCodecParameters(const AVStream &stream)
GetCodecParameters(const AVStream &stream) noexcept
{
return *stream.codecpar;
}
gcc_pure
static AVSampleFormat
GetSampleFormat(const AVCodecParameters &codec_params)
GetSampleFormat(const AVCodecParameters &codec_params) noexcept
{
return AVSampleFormat(codec_params.format);
}
@@ -128,14 +128,14 @@ GetSampleFormat(const AVCodecParameters &codec_params)
gcc_pure
static const AVCodecContext &
GetCodecParameters(const AVStream &stream)
GetCodecParameters(const AVStream &stream) noexcept
{
return *stream.codec;
}
gcc_pure
static AVSampleFormat
GetSampleFormat(const AVCodecContext &codec_context)
GetSampleFormat(const AVCodecContext &codec_context) noexcept
{
return codec_context.sample_fmt;
}
@@ -144,14 +144,14 @@ GetSampleFormat(const AVCodecContext &codec_context)
gcc_pure
static bool
IsAudio(const AVStream &stream)
IsAudio(const AVStream &stream) noexcept
{
return GetCodecParameters(stream).codec_type == AVMEDIA_TYPE_AUDIO;
}
gcc_pure
static int
ffmpeg_find_audio_stream(const AVFormatContext &format_context)
ffmpeg_find_audio_stream(const AVFormatContext &format_context) noexcept
{
for (unsigned i = 0; i < format_context.nb_streams; ++i)
if (IsAudio(*format_context.streams[i]))
@@ -220,7 +220,7 @@ copy_interleave_frame(const AVCodecContext &codec_context,
*/
gcc_pure
static int64_t
StreamRelativePts(const AVPacket &packet, const AVStream &stream)
StreamRelativePts(const AVPacket &packet, const AVStream &stream) noexcept
{
auto pts = packet.pts;
if (pts < 0 || pts == int64_t(AV_NOPTS_VALUE))
@@ -237,7 +237,7 @@ StreamRelativePts(const AVPacket &packet, const AVStream &stream)
gcc_pure
static uint64_t
PtsToPcmFrame(uint64_t pts, const AVStream &stream,
const AVCodecContext &codec_context)
const AVCodecContext &codec_context) noexcept
{
return av_rescale_q(pts, stream.time_base, codec_context.time_base);
}
@@ -437,7 +437,7 @@ ffmpeg_send_packet(DecoderClient &client, InputStream &is,
gcc_const
static SampleFormat
ffmpeg_sample_format(enum AVSampleFormat sample_fmt)
ffmpeg_sample_format(enum AVSampleFormat sample_fmt) noexcept
{
switch (sample_fmt) {
case AV_SAMPLE_FMT_S16:

View File

@@ -67,7 +67,7 @@ flac_parse_mixramp(const FLAC__StreamMetadata_VorbisComment &vc)
*/
static const char *
flac_comment_value(const FLAC__StreamMetadata_VorbisComment_Entry *entry,
const char *name)
const char *name) noexcept
{
return vorbis_comment_value((const char *)entry->entry, name);
}
@@ -126,7 +126,7 @@ flac_scan_comments(const FLAC__StreamMetadata_VorbisComment *comment,
gcc_pure
static inline SongTime
flac_duration(const FLAC__StreamMetadata_StreamInfo *stream_info)
flac_duration(const FLAC__StreamMetadata_StreamInfo *stream_info) noexcept
{
assert(stream_info->sample_rate > 0);

View File

@@ -74,7 +74,7 @@ gme_plugin_init(gcc_unused const ConfigBlock &block)
gcc_pure
static unsigned
ParseSubtuneName(const char *base)
ParseSubtuneName(const char *base) noexcept
{
if (memcmp(base, SUBTUNE_PREFIX, sizeof(SUBTUNE_PREFIX) - 1) != 0)
return 0;

View File

@@ -71,7 +71,7 @@ static bool gapless_playback;
gcc_const
static SongTime
ToSongTime(mad_timer_t t)
ToSongTime(mad_timer_t t) noexcept
{
return SongTime::FromMS(mad_timer_count(t, MAD_UNITS_MILLISECONDS));
}
@@ -155,10 +155,10 @@ struct MadDecoder {
enum mp3_action DecodeNextFrame();
gcc_pure
offset_type ThisFrameOffset() const;
offset_type ThisFrameOffset() const noexcept;
gcc_pure
offset_type RestIncludingThisFrame() const;
offset_type RestIncludingThisFrame() const noexcept;
/**
* Attempt to calulcate the length of the song from filesize
@@ -177,7 +177,7 @@ struct MadDecoder {
}
gcc_pure
long TimeToFrame(SongTime t) const;
long TimeToFrame(SongTime t) const noexcept;
void UpdateTimerNextFrame();
@@ -291,7 +291,7 @@ parse_id3_replay_gain_info(ReplayGainInfo &rgi,
#ifdef ENABLE_ID3TAG
gcc_pure
static MixRampInfo
parse_id3_mixramp(struct id3_tag *tag)
parse_id3_mixramp(struct id3_tag *tag) noexcept
{
MixRampInfo result;
@@ -710,7 +710,7 @@ mp3_frame_duration(const struct mad_frame *frame)
}
inline offset_type
MadDecoder::ThisFrameOffset() const
MadDecoder::ThisFrameOffset() const noexcept
{
auto offset = input_stream.GetOffset();
@@ -723,7 +723,7 @@ MadDecoder::ThisFrameOffset() const
}
inline offset_type
MadDecoder::RestIncludingThisFrame() const
MadDecoder::RestIncludingThisFrame() const noexcept
{
return input_stream.GetSize() - ThisFrameOffset();
}
@@ -846,7 +846,7 @@ mad_decoder_total_file_time(InputStream &is)
}
long
MadDecoder::TimeToFrame(SongTime t) const
MadDecoder::TimeToFrame(SongTime t) const noexcept
{
unsigned long i;

View File

@@ -31,7 +31,7 @@
gcc_pure
static TagType
ParseOpusTagName(const char *name)
ParseOpusTagName(const char *name) noexcept
{
TagType type = tag_name_parse_i(name);
if (type != TAG_NUM_OF_ITEM_TYPES)

View File

@@ -116,7 +116,7 @@ struct SidplayContainerPath {
gcc_pure
static unsigned
ParseSubtuneName(const char *base)
ParseSubtuneName(const char *base) noexcept
{
if (memcmp(base, SUBTUNE_PREFIX, sizeof(SUBTUNE_PREFIX) - 1) != 0)
return 0;
@@ -390,7 +390,7 @@ sidplay_file_decode(DecoderClient &client, Path path_fs)
gcc_pure
static const char *
GetInfoString(const SidTuneInfo &info, unsigned i)
GetInfoString(const SidTuneInfo &info, unsigned i) noexcept
{
#ifdef HAVE_SIDPLAYFP
return info.numberOfInfoStrings() > i

View File

@@ -148,7 +148,7 @@ sndfile_duration(const SF_INFO &info)
gcc_pure
static SampleFormat
sndfile_sample_format(const SF_INFO &info)
sndfile_sample_format(const SF_INFO &info) noexcept
{
switch (info.format & SF_FORMAT_SUBMASK) {
case SF_FORMAT_PCM_S8:

View File

@@ -101,7 +101,7 @@ WavpackOpenInput(WavpackStreamReader *reader, void *wv_id, void *wvc_id,
gcc_pure
static SignedSongTime
GetDuration(WavpackContext *wpc)
GetDuration(WavpackContext *wpc) noexcept
{
#ifdef OPEN_DSD_AS_PCM
/* libWavPack 5 */