*: 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

@@ -45,7 +45,7 @@ extern ThreadId db_mutex_holder;
*/
gcc_pure
static inline bool
holding_db_lock(void)
holding_db_lock() noexcept
{
return db_mutex_holder.IsInside();
}

View File

@@ -21,7 +21,7 @@
#include "tag/Tag.hxx"
SignedSongTime
LightSong::GetDuration() const
LightSong::GetDuration() const noexcept
{
SongTime a = start_time, b = end_time;
if (!b.IsPositive()) {

View File

@@ -76,7 +76,7 @@ struct LightSong {
SongTime end_time;
gcc_pure
std::string GetURI() const {
std::string GetURI() const noexcept {
if (directory == nullptr)
return std::string(uri);
@@ -87,7 +87,7 @@ struct LightSong {
}
gcc_pure
SignedSongTime GetDuration() const;
SignedSongTime GetDuration() const noexcept;
};
#endif

View File

@@ -26,7 +26,7 @@
#include <assert.h>
PlaylistVector::iterator
PlaylistVector::find(const char *name)
PlaylistVector::find(const char *name) noexcept
{
assert(holding_db_lock());
assert(name != nullptr);

View File

@@ -31,7 +31,7 @@ protected:
* Caller must lock the #db_mutex.
*/
gcc_pure
iterator find(const char *name);
iterator find(const char *name) noexcept;
public:
using std::list<PlaylistInfo>::empty;

View File

@@ -38,7 +38,7 @@ const DatabasePlugin *const database_plugins[] = {
};
const DatabasePlugin *
GetDatabasePluginByName(const char *name)
GetDatabasePluginByName(const char *name) noexcept
{
for (auto i = database_plugins; *i != nullptr; ++i)
if (strcmp((*i)->name, name) == 0)

View File

@@ -32,6 +32,6 @@ extern const DatabasePlugin *const database_plugins[];
gcc_pure
const DatabasePlugin *
GetDatabasePluginByName(const char *name);
GetDatabasePluginByName(const char *name) noexcept;
#endif

View File

@@ -34,19 +34,19 @@ DatabaseSelection::DatabaseSelection(const char *_uri, bool _recursive,
}
bool
DatabaseSelection::IsEmpty() const
DatabaseSelection::IsEmpty() const noexcept
{
return uri.empty() && (filter == nullptr || filter->IsEmpty());
}
bool
DatabaseSelection::HasOtherThanBase() const
DatabaseSelection::HasOtherThanBase() const noexcept
{
return filter != nullptr && filter->HasOtherThanBase();
}
bool
DatabaseSelection::Match(const LightSong &song) const
DatabaseSelection::Match(const LightSong &song) const noexcept
{
return filter == nullptr || filter->Match(song);
}

View File

@@ -45,16 +45,16 @@ struct DatabaseSelection {
const SongFilter *_filter=nullptr);
gcc_pure
bool IsEmpty() const;
bool IsEmpty() const noexcept;
/**
* Does this selection contain constraints other than "base"?
*/
gcc_pure
bool HasOtherThanBase() const;
bool HasOtherThanBase() const noexcept;
gcc_pure
bool Match(const LightSong &song) const;
bool Match(const LightSong &song) const noexcept;
};
#endif

View File

@@ -216,7 +216,7 @@ ProxySong::ProxySong(const mpd_song *song)
gcc_const
static enum mpd_tag_type
Convert(TagType tag_type)
Convert(TagType tag_type) noexcept
{
for (auto i = &tag_table[0]; i->d != TAG_NUM_OF_ITEM_TYPES; ++i)
if (i->d == tag_type)
@@ -574,7 +574,7 @@ Visit(struct mpd_connection *connection,
gcc_pure
static bool
Match(const SongFilter *filter, const LightSong &song)
Match(const SongFilter *filter, const LightSong &song) noexcept
{
return filter == nullptr || filter->Match(song);
}
@@ -717,7 +717,7 @@ SearchSongs(struct mpd_connection *connection,
*/
gcc_pure
static bool
ServerSupportsSearchBase(const struct mpd_connection *connection)
ServerSupportsSearchBase(const struct mpd_connection *connection) noexcept
{
#if LIBMPDCLIENT_CHECK_VERSION(2,9,0)
return mpd_connection_cmp_server_version(connection, 0, 18, 0) >= 0;

View File

@@ -65,7 +65,7 @@ Directory::Delete()
}
const char *
Directory::GetName() const
Directory::GetName() const noexcept
{
assert(!IsRoot());
@@ -89,7 +89,7 @@ Directory::CreateChild(const char *name_utf8)
}
const Directory *
Directory::FindChild(const char *name) const
Directory::FindChild(const char *name) const noexcept
{
assert(holding_db_lock());
@@ -101,7 +101,7 @@ Directory::FindChild(const char *name) const
}
void
Directory::PruneEmpty()
Directory::PruneEmpty() noexcept
{
assert(holding_db_lock());
@@ -118,7 +118,7 @@ Directory::PruneEmpty()
}
Directory::LookupResult
Directory::LookupDirectory(const char *uri)
Directory::LookupDirectory(const char *uri) noexcept
{
assert(holding_db_lock());
assert(uri != nullptr);
@@ -173,7 +173,7 @@ Directory::AddSong(Song *song)
}
void
Directory::RemoveSong(Song *song)
Directory::RemoveSong(Song *song) noexcept
{
assert(holding_db_lock());
assert(song != nullptr);
@@ -183,7 +183,7 @@ Directory::RemoveSong(Song *song)
}
const Song *
Directory::FindSong(const char *name_utf8) const
Directory::FindSong(const char *name_utf8) const noexcept
{
assert(holding_db_lock());
assert(name_utf8 != nullptr);
@@ -200,13 +200,13 @@ Directory::FindSong(const char *name_utf8) const
gcc_pure
static bool
directory_cmp(const Directory &a, const Directory &b)
directory_cmp(const Directory &a, const Directory &b) noexcept
{
return IcuCollate(a.path.c_str(), b.path.c_str()) < 0;
}
void
Directory::Sort()
Directory::Sort() noexcept
{
assert(holding_db_lock());
@@ -261,7 +261,7 @@ Directory::Walk(bool recursive, const SongFilter *filter,
}
LightDirectory
Directory::Export() const
Directory::Export() const noexcept
{
return LightDirectory(GetPath(), mtime);
}

View File

@@ -134,10 +134,10 @@ public:
* Caller must lock the #db_mutex.
*/
gcc_pure
const Directory *FindChild(const char *name) const;
const Directory *FindChild(const char *name) const noexcept;
gcc_pure
Directory *FindChild(const char *name) {
Directory *FindChild(const char *name) noexcept {
const Directory *cthis = this;
return const_cast<Directory *>(cthis->FindChild(name));
}
@@ -177,10 +177,10 @@ public:
* @return the Directory, or nullptr if none was found
*/
gcc_pure
LookupResult LookupDirectory(const char *uri);
LookupResult LookupDirectory(const char *uri) noexcept;
gcc_pure
bool IsEmpty() const {
bool IsEmpty() const noexcept {
return children.empty() &&
songs.empty() &&
playlists.empty();
@@ -195,13 +195,13 @@ public:
* Returns the base name of the directory.
*/
gcc_pure
const char *GetName() const;
const char *GetName() const noexcept;
/**
* Is this the root directory of the music database?
*/
gcc_pure
bool IsRoot() const {
bool IsRoot() const noexcept {
return parent == nullptr;
}
@@ -229,10 +229,10 @@ public:
* Caller must lock the #db_mutex.
*/
gcc_pure
const Song *FindSong(const char *name_utf8) const;
const Song *FindSong(const char *name_utf8) const noexcept;
gcc_pure
Song *FindSong(const char *name_utf8) {
Song *FindSong(const char *name_utf8) noexcept {
const Directory *cthis = this;
return const_cast<Song *>(cthis->FindSong(name_utf8));
}
@@ -248,19 +248,19 @@ public:
* invalidates the song object, because the "parent" attribute becomes
* stale), but does not free it.
*/
void RemoveSong(Song *song);
void RemoveSong(Song *song) noexcept;
/**
* Caller must lock the #db_mutex.
*/
void PruneEmpty();
void PruneEmpty() noexcept;
/**
* Sort all directory entries recursively.
*
* Caller must lock the #db_mutex.
*/
void Sort();
void Sort() noexcept;
/**
* Caller must lock #db_mutex.
@@ -270,7 +270,7 @@ public:
VisitPlaylist visit_playlist) const;
gcc_pure
LightDirectory Export() const;
LightDirectory Export() const noexcept;
};
#endif

View File

@@ -40,7 +40,7 @@
gcc_const
static const char *
DeviceToTypeString(unsigned device)
DeviceToTypeString(unsigned device) noexcept
{
switch (device) {
case DEVICE_INARCHIVE:
@@ -56,7 +56,7 @@ DeviceToTypeString(unsigned device)
gcc_pure
static unsigned
ParseTypeString(const char *type)
ParseTypeString(const char *type) noexcept
{
if (strcmp(type, "archive") == 0)
return DEVICE_INARCHIVE;

View File

@@ -77,7 +77,7 @@ Song::Free()
}
std::string
Song::GetURI() const
Song::GetURI() const noexcept
{
assert(*uri);
@@ -96,7 +96,7 @@ Song::GetURI() const
}
LightSong
Song::Export() const
Song::Export() const noexcept
{
LightSong dest;
dest.directory = parent->IsRoot()

View File

@@ -123,10 +123,10 @@ struct Song {
* location within the music directory.
*/
gcc_pure
std::string GetURI() const;
std::string GetURI() const noexcept;
gcc_pure
LightSong Export() const;
LightSong Export() const noexcept;
};
typedef boost::intrusive::list<Song,

View File

@@ -26,7 +26,7 @@
#include <stdlib.h>
static int
compare_utf8_string(const char *a, const char *b)
compare_utf8_string(const char *a, const char *b) noexcept
{
if (a == nullptr)
return b == nullptr ? 0 : -1;
@@ -42,8 +42,7 @@ compare_utf8_string(const char *a, const char *b)
* nullptr.
*/
static int
compare_string_tag_item(const Tag &a, const Tag &b,
TagType type)
compare_string_tag_item(const Tag &a, const Tag &b, TagType type) noexcept
{
return compare_utf8_string(a.GetValue(type),
b.GetValue(type));
@@ -54,7 +53,7 @@ compare_string_tag_item(const Tag &a, const Tag &b,
* (e.g. disc or track number). Either one may be nullptr.
*/
static int
compare_number_string(const char *a, const char *b)
compare_number_string(const char *a, const char *b) noexcept
{
long ai = a == nullptr ? 0 : strtol(a, nullptr, 10);
long bi = b == nullptr ? 0 : strtol(b, nullptr, 10);
@@ -69,7 +68,7 @@ compare_number_string(const char *a, const char *b)
}
static int
compare_tag_item(const Tag &a, const Tag &b, TagType type)
compare_tag_item(const Tag &a, const Tag &b, TagType type) noexcept
{
return compare_number_string(a.GetValue(type),
b.GetValue(type));
@@ -78,7 +77,7 @@ compare_tag_item(const Tag &a, const Tag &b, TagType type)
/* Only used for sorting/searchin a songvec, not general purpose compares */
gcc_pure
static bool
song_cmp(const Song &a, const Song &b)
song_cmp(const Song &a, const Song &b) noexcept
{
int ret;
@@ -102,7 +101,7 @@ song_cmp(const Song &a, const Song &b)
}
void
song_list_sort(SongList &songs)
song_list_sort(SongList &songs) noexcept
{
songs.sort(song_cmp);
}

View File

@@ -23,6 +23,6 @@
#include "Song.hxx"
void
song_list_sort(SongList &songs);
song_list_sort(SongList &songs) noexcept;
#endif

View File

@@ -39,7 +39,7 @@ UPnPDirContent::~UPnPDirContent()
gcc_pure
static UPnPDirObject::ItemClass
ParseItemClass(StringView name)
ParseItemClass(StringView name) noexcept
{
if (name.EqualsLiteral("object.item.audioItem.musicTrack"))
return UPnPDirObject::ItemClass::MUSIC;
@@ -51,7 +51,7 @@ ParseItemClass(StringView name)
gcc_pure
static SignedSongTime
ParseDuration(const char *duration)
ParseDuration(const char *duration) noexcept
{
char *endptr;
@@ -81,7 +81,7 @@ ParseDuration(const char *duration)
*/
gcc_pure
static std::string &&
TitleToPathSegment(std::string &&s)
TitleToPathSegment(std::string &&s) noexcept
{
std::replace(s.begin(), s.end(), '/', '_');
return std::move(s);

View File

@@ -40,7 +40,7 @@ public:
~UPnPDirContent();
gcc_pure
UPnPDirObject *FindObject(const char *name) {
UPnPDirObject *FindObject(const char *name) noexcept {
for (auto &o : objects)
if (o.name == name)
return &o;

View File

@@ -56,7 +56,7 @@ InotifyQueue::OnTimeout()
gcc_pure
static bool
path_in(const char *path, const char *possible_parent)
path_in(const char *path, const char *possible_parent) noexcept
{
if (StringIsEmpty(path))
return true;

View File

@@ -62,10 +62,10 @@ struct WatchDirectory {
WatchDirectory &operator=(const WatchDirectory &) = delete;
gcc_pure
unsigned GetDepth() const;
unsigned GetDepth() const noexcept;
gcc_pure
AllocatedPath GetUriFS() const;
AllocatedPath GetUriFS() const noexcept;
};
static InotifySource *inotify_source;
@@ -132,7 +132,7 @@ remove_watch_directory(WatchDirectory *directory)
}
AllocatedPath
WatchDirectory::GetUriFS() const
WatchDirectory::GetUriFS() const noexcept
{
if (parent == nullptr)
return AllocatedPath::Null();
@@ -225,7 +225,7 @@ recursive_watch_subdirectories(WatchDirectory *directory,
gcc_pure
unsigned
WatchDirectory::GetDepth() const
WatchDirectory::GetDepth() const noexcept
{
const WatchDirectory *d = this;
unsigned depth = 0;
@@ -331,7 +331,7 @@ mpd_inotify_init(EventLoop &loop, Storage &storage, UpdateService &update,
}
void
mpd_inotify_finish(void)
mpd_inotify_finish(void) noexcept
{
if (inotify_source == nullptr)
return;

View File

@@ -32,6 +32,6 @@ mpd_inotify_init(EventLoop &loop, Storage &storage, UpdateService &update,
unsigned max_depth);
void
mpd_inotify_finish();
mpd_inotify_finish() noexcept;
#endif

View File

@@ -32,7 +32,7 @@
#include <errno.h>
bool
GetInfo(Storage &storage, const char *uri_utf8, StorageFileInfo &info)
GetInfo(Storage &storage, const char *uri_utf8, StorageFileInfo &info) noexcept
try {
info = storage.GetInfo(uri_utf8, true);
return true;
@@ -42,7 +42,7 @@ try {
}
bool
GetInfo(StorageDirectoryReader &reader, StorageFileInfo &info)
GetInfo(StorageDirectoryReader &reader, StorageFileInfo &info) noexcept
try {
info = reader.GetInfo(true);
return true;
@@ -52,7 +52,7 @@ try {
}
bool
DirectoryExists(Storage &storage, const Directory &directory)
DirectoryExists(Storage &storage, const Directory &directory) noexcept
{
StorageFileInfo info;
@@ -79,7 +79,7 @@ GetDirectoryChildInfo(Storage &storage, const Directory &directory,
bool
directory_child_is_regular(Storage &storage, const Directory &directory,
const char *name_utf8)
const char *name_utf8) noexcept
try {
return GetDirectoryChildInfo(storage, directory, name_utf8)
.IsRegular();
@@ -89,7 +89,7 @@ try {
bool
directory_child_access(Storage &storage, const Directory &directory,
const char *name, int mode)
const char *name, int mode) noexcept
{
#ifdef WIN32
/* CheckAccess() is useless on WIN32 */

View File

@@ -33,23 +33,23 @@ class StorageDirectoryReader;
* returning them.
*/
bool
GetInfo(Storage &storage, const char *uri_utf8, StorageFileInfo &info);
GetInfo(Storage &storage, const char *uri_utf8, StorageFileInfo &info) noexcept;
/**
* Wrapper for LocalDirectoryReader::GetInfo() that logs errors
* instead of returning them.
*/
bool
GetInfo(StorageDirectoryReader &reader, StorageFileInfo &info);
GetInfo(StorageDirectoryReader &reader, StorageFileInfo &info) noexcept;
gcc_pure
bool
DirectoryExists(Storage &storage, const Directory &directory);
DirectoryExists(Storage &storage, const Directory &directory) noexcept;
gcc_pure
bool
directory_child_is_regular(Storage &storage, const Directory &directory,
const char *name_utf8);
const char *name_utf8) noexcept;
/**
* Checks if the given permissions on the mapped file are given.
@@ -57,6 +57,6 @@ directory_child_is_regular(Storage &storage, const Directory &directory,
gcc_pure
bool
directory_child_access(Storage &storage, const Directory &directory,
const char *name, int mode);
const char *name, int mode) noexcept;
#endif

View File

@@ -248,7 +248,7 @@ try {
/* we don't look at "." / ".." nor files with newlines in their name */
gcc_pure
static bool
skip_path(const char *name_utf8)
skip_path(const char *name_utf8) noexcept
{
return strchr(name_utf8, '\n') != nullptr;
}
@@ -256,7 +256,7 @@ skip_path(const char *name_utf8)
gcc_pure
bool
UpdateWalk::SkipSymlink(const Directory *directory,
const char *utf8_name) const
const char *utf8_name) const noexcept
{
#ifndef WIN32
const auto path_fs = storage.MapChildFS(directory->GetPath(),

View File

@@ -78,7 +78,7 @@ public:
private:
gcc_pure
bool SkipSymlink(const Directory *directory,
const char *utf8_name) const;
const char *utf8_name) const noexcept;
void RemoveExcludedFromDirectory(Directory &directory,
const ExcludeList &exclude_list);