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

@@ -170,7 +170,7 @@ CurlRequest::Done(CURLcode result)
gcc_pure
static bool
IsResponseBoundaryHeader(StringView s)
IsResponseBoundaryHeader(StringView s) noexcept
{
return s.size > 5 && (memcmp(s.data, "HTTP/", 5) == 0 ||
/* the proprietary "ICY 200 OK" is

View File

@@ -32,7 +32,7 @@
#include <curl/curl.h>
bool
IsCurlOlderThan(unsigned version_num)
IsCurlOlderThan(unsigned version_num) noexcept
{
const auto *const info = curl_version_info(CURLVERSION_FIRST);
return info == nullptr || info->version_num < version_num;

View File

@@ -34,6 +34,6 @@
gcc_const
bool
IsCurlOlderThan(unsigned version_num);
IsCurlOlderThan(unsigned version_num) noexcept;
#endif

View File

@@ -32,7 +32,7 @@ ExpatParser::Parse(const char *data, size_t length, bool is_final)
const char *
ExpatParser::GetAttribute(const XML_Char **atts,
const char *name)
const char *name) noexcept
{
for (unsigned i = 0; atts[i] != nullptr; i += 2)
if (strcmp(atts[i], name) == 0)
@@ -43,7 +43,7 @@ ExpatParser::GetAttribute(const XML_Char **atts,
const char *
ExpatParser::GetAttributeCase(const XML_Char **atts,
const char *name)
const char *name) noexcept
{
for (unsigned i = 0; atts[i] != nullptr; i += 2)
if (StringEqualsCaseASCII(atts[i], name))

View File

@@ -64,11 +64,11 @@ public:
ExpatParser &operator=(const ExpatParser &) = delete;
void SetElementHandler(XML_StartElementHandler start,
XML_EndElementHandler end) {
XML_EndElementHandler end) noexcept {
XML_SetElementHandler(parser, start, end);
}
void SetCharacterDataHandler(XML_CharacterDataHandler charhndl) {
void SetCharacterDataHandler(XML_CharacterDataHandler charhndl) noexcept {
XML_SetCharacterDataHandler(parser, charhndl);
}
@@ -78,11 +78,11 @@ public:
gcc_pure
static const char *GetAttribute(const XML_Char **atts,
const char *name);
const char *name) noexcept;
gcc_pure
static const char *GetAttributeCase(const XML_Char **atts,
const char *name);
const char *name) noexcept;
};
/**
@@ -114,13 +114,13 @@ public:
gcc_pure
static const char *GetAttribute(const XML_Char **atts,
const char *name) {
const char *name) noexcept {
return ExpatParser::GetAttribute(atts, name);
}
gcc_pure
static const char *GetAttributeCase(const XML_Char **atts,
const char *name) {
const char *name) noexcept {
return ExpatParser::GetAttributeCase(atts, name);
}

View File

@@ -34,7 +34,7 @@ extern "C" {
gcc_const
static LogLevel
FfmpegImportLogLevel(int level)
FfmpegImportLogLevel(int level) noexcept
{
if (level <= AV_LOG_FATAL)
return LogLevel::ERROR;

View File

@@ -41,7 +41,7 @@ extern "C" {
*/
gcc_const
static inline double
FfmpegTimeToDouble(int64_t t, const AVRational time_base)
FfmpegTimeToDouble(int64_t t, const AVRational time_base) noexcept
{
assert(t != (int64_t)AV_NOPTS_VALUE);
@@ -64,7 +64,7 @@ RatioToAVRational()
*/
gcc_const
static inline SongTime
FromFfmpegTime(int64_t t, const AVRational time_base)
FromFfmpegTime(int64_t t, const AVRational time_base) noexcept
{
assert(t != (int64_t)AV_NOPTS_VALUE);
@@ -77,7 +77,7 @@ FromFfmpegTime(int64_t t, const AVRational time_base)
*/
gcc_const
static inline SignedSongTime
FromFfmpegTimeChecked(int64_t t, const AVRational time_base)
FromFfmpegTimeChecked(int64_t t, const AVRational time_base) noexcept
{
return t != (int64_t)AV_NOPTS_VALUE
? SignedSongTime(FromFfmpegTime(t, time_base))
@@ -89,7 +89,7 @@ FromFfmpegTimeChecked(int64_t t, const AVRational time_base)
*/
gcc_const
static inline int64_t
ToFfmpegTime(SongTime t, const AVRational time_base)
ToFfmpegTime(SongTime t, const AVRational time_base) noexcept
{
return av_rescale_q(t.count(),
RatioToAVRational<SongTime::period>(),

View File

@@ -65,7 +65,7 @@ IcuCollateInit()
}
void
IcuCollateFinish()
IcuCollateFinish() noexcept
{
assert(collator != nullptr);
@@ -76,7 +76,7 @@ IcuCollateFinish()
gcc_pure
int
IcuCollate(const char *a, const char *b)
IcuCollate(const char *a, const char *b) noexcept
{
#if !CLANG_CHECK_VERSION(3,6)
/* disabled on clang due to -Wtautological-pointer-compare */

View File

@@ -32,11 +32,11 @@ void
IcuCollateInit();
void
IcuCollateFinish();
IcuCollateFinish() noexcept;
gcc_pure gcc_nonnull_all
int
IcuCollate(const char *a, const char *b);
IcuCollate(const char *a, const char *b) noexcept;
gcc_pure gcc_nonnull_all
AllocatedString<char>

View File

@@ -46,7 +46,7 @@ nfs_set_base(const char *server, const char *export_name)
}
const char *
nfs_check_base(const char *server, const char *path)
nfs_check_base(const char *server, const char *path) noexcept
{
assert(server != nullptr);
assert(path != nullptr);

View File

@@ -41,6 +41,6 @@ nfs_set_base(const char *server, const char *export_name);
*/
gcc_pure
const char *
nfs_check_base(const char *server, const char *path);
nfs_check_base(const char *server, const char *path) noexcept;
#endif

View File

@@ -91,29 +91,29 @@ private:
};
gcc_pure
iterator Find(reference_type p) {
iterator Find(reference_type p) noexcept {
return std::find_if(list.begin(), list.end(), MatchPointer(p));
}
gcc_pure
const_iterator Find(const_reference_type p) const {
const_iterator Find(const_reference_type p) const noexcept {
return std::find_if(list.begin(), list.end(), MatchPointer(p));
}
gcc_pure
iterator Find(CT &c) {
iterator Find(CT &c) noexcept {
return list.iterator_to(c);
}
gcc_pure
const_iterator Find(const CT &c) const {
const_iterator Find(const CT &c) const noexcept {
return list.iterator_to(c);
}
public:
#ifndef NDEBUG
gcc_pure
bool IsEmpty() const {
bool IsEmpty() const noexcept {
for (const auto &c : list)
if (!c.IsCancelled())
return false;
@@ -123,7 +123,7 @@ public:
#endif
gcc_pure
bool Contains(const_reference_type p) const {
bool Contains(const_reference_type p) const noexcept {
return Find(p) != list.end();
}
@@ -151,7 +151,7 @@ public:
i->Cancel();
}
CT &Get(reference_type p) {
CT &Get(reference_type p) noexcept {
auto i = Find(p);
assert(i != list.end());

View File

@@ -135,7 +135,7 @@ class NfsConnection : SocketMonitor, TimeoutMonitor, DeferredMonitor {
public:
gcc_nonnull_all
NfsConnection(EventLoop &_loop,
const char *_server, const char *_export_name)
const char *_server, const char *_export_name) noexcept
:SocketMonitor(_loop), TimeoutMonitor(_loop),
DeferredMonitor(_loop),
server(_server), export_name(_export_name),

View File

@@ -50,7 +50,7 @@ nfs_finish()
}
NfsConnection &
nfs_get_connection(const char *server, const char *export_name)
nfs_get_connection(const char *server, const char *export_name) noexcept
{
assert(in_use > 0);
assert(io_thread_inside());

View File

@@ -33,6 +33,6 @@ nfs_finish();
gcc_pure
NfsConnection &
nfs_get_connection(const char *server, const char *export_name);
nfs_get_connection(const char *server, const char *export_name) noexcept;
#endif

View File

@@ -38,7 +38,7 @@ NfsManager::ManagedConnection::OnNfsConnectionError(std::exception_ptr &&e)
inline bool
NfsManager::Compare::operator()(const LookupKey a,
const ManagedConnection &b) const
const ManagedConnection &b) const noexcept
{
int result = strcmp(a.server, b.GetServer());
if (result != 0)
@@ -50,7 +50,7 @@ NfsManager::Compare::operator()(const LookupKey a,
inline bool
NfsManager::Compare::operator()(const ManagedConnection &a,
const LookupKey b) const
const LookupKey b) const noexcept
{
int result = strcmp(a.GetServer(), b.server);
if (result != 0)
@@ -62,7 +62,7 @@ NfsManager::Compare::operator()(const ManagedConnection &a,
inline bool
NfsManager::Compare::operator()(const ManagedConnection &a,
const ManagedConnection &b) const
const ManagedConnection &b) const noexcept
{
int result = strcmp(a.GetServer(), b.GetServer());
if (result != 0)
@@ -82,7 +82,7 @@ NfsManager::~NfsManager()
}
NfsConnection &
NfsManager::GetConnection(const char *server, const char *export_name)
NfsManager::GetConnection(const char *server, const char *export_name) noexcept
{
assert(server != nullptr);
assert(export_name != nullptr);

View File

@@ -59,15 +59,15 @@ class NfsManager final : IdleMonitor {
struct Compare {
gcc_pure
bool operator()(const LookupKey a,
const ManagedConnection &b) const;
const ManagedConnection &b) const noexcept;
gcc_pure
bool operator()(const ManagedConnection &a,
const LookupKey b) const;
const LookupKey b) const noexcept;
gcc_pure
bool operator()(const ManagedConnection &a,
const ManagedConnection &b) const;
const ManagedConnection &b) const noexcept;
};
/**
@@ -99,7 +99,7 @@ public:
gcc_pure
NfsConnection &GetConnection(const char *server,
const char *export_name);
const char *export_name) noexcept;
private:
void ScheduleDelete(ManagedConnection &c) {

View File

@@ -36,7 +36,7 @@ static constexpr char ContentDirectorySType[] = "urn:schemas-upnp-org:service:Co
// version 1
gcc_pure
static bool
isCDService(const char *st)
isCDService(const char *st) noexcept
{
constexpr size_t sz = sizeof(ContentDirectorySType) - 3;
return memcmp(ContentDirectorySType, st, sz) == 0;
@@ -47,7 +47,7 @@ static constexpr char MediaServerDType[] = "urn:schemas-upnp-org:device:MediaSer
gcc_pure
static bool
isMSDevice(const char *st)
isMSDevice(const char *st) noexcept
{
constexpr size_t sz = sizeof(MediaServerDType) - 3;
return memcmp(MediaServerDType, st, sz) == 0;

View File

@@ -23,7 +23,7 @@
/** Get rid of white space at both ends */
void
trimstring(std::string &s, const char *ws)
trimstring(std::string &s, const char *ws) noexcept
{
auto pos = s.find_first_not_of(ws);
if (pos == std::string::npos) {
@@ -38,14 +38,14 @@ trimstring(std::string &s, const char *ws)
}
static void
path_catslash(std::string &s)
path_catslash(std::string &s) noexcept
{
if (s.empty() || s.back() != '/')
s += '/';
}
std::string
path_getfather(const std::string &s)
path_getfather(const std::string &s) noexcept
{
std::string father = s;
@@ -71,7 +71,7 @@ path_getfather(const std::string &s)
std::list<std::string>
stringToTokens(const std::string &str,
const char delim)
const char delim) noexcept
{
std::list<std::string> tokens;
@@ -105,7 +105,7 @@ stringToTokens(const std::string &str,
template <class T>
bool
csvToStrings(const char *s, T &tokens)
csvToStrings(const char *s, T &tokens) noexcept
{
assert(tokens.empty());
@@ -132,4 +132,4 @@ csvToStrings(const char *s, T &tokens)
}
}
template bool csvToStrings<std::list<std::string>>(const char *, std::list<std::string> &);
template bool csvToStrings<std::list<std::string>>(const char *, std::list<std::string> &) noexcept;

View File

@@ -26,17 +26,17 @@
#include <list>
void
trimstring(std::string &s, const char *ws = " \t\n");
trimstring(std::string &s, const char *ws = " \t\n") noexcept;
std::string
path_getfather(const std::string &s);
path_getfather(const std::string &s) noexcept;
gcc_pure
std::list<std::string>
stringToTokens(const std::string &str, char delim);
stringToTokens(const std::string &str, char delim) noexcept;
template <class T>
bool
csvToStrings(const char *s, T &tokens);
csvToStrings(const char *s, T &tokens) noexcept;
#endif /* _UPNPP_H_X_INCLUDED_ */