more [[gnu::...]] attributes

This commit is contained in:
Max Kellermann
2021-10-13 11:28:04 +02:00
parent 1c4b484a56
commit f510564d9d
135 changed files with 361 additions and 514 deletions

View File

@@ -43,7 +43,7 @@
* enum. Returns SND_PCM_FORMAT_UNKNOWN if there is no according ALSA
* PCM format.
*/
gcc_const
[[gnu::const]]
inline snd_pcm_format_t
ToAlsaPcmFormat(SampleFormat sample_format) noexcept
{
@@ -82,7 +82,7 @@ ToAlsaPcmFormat(SampleFormat sample_format) noexcept
* Determine the byte-swapped PCM format. Returns
* SND_PCM_FORMAT_UNKNOWN if the format cannot be byte-swapped.
*/
gcc_const
[[gnu::const]]
inline snd_pcm_format_t
ByteSwapAlsaPcmFormat(snd_pcm_format_t fmt) noexcept
{
@@ -123,8 +123,7 @@ ByteSwapAlsaPcmFormat(snd_pcm_format_t fmt) noexcept
* Check if there is a "packed" version of the give PCM format.
* Returns SND_PCM_FORMAT_UNKNOWN if not.
*/
gcc_const
inline snd_pcm_format_t
constexpr snd_pcm_format_t
PackAlsaPcmFormat(snd_pcm_format_t fmt) noexcept
{
switch (fmt) {

View File

@@ -23,7 +23,7 @@
#include <stdlib.h>
gcc_pure
[[gnu::pure]]
static uint_least32_t
ParseAlsaVersion(const char *p) noexcept
{

View File

@@ -20,8 +20,6 @@
#ifndef MPD_ALSA_VERSION_HXX
#define MPD_ALSA_VERSION_HXX
#include "util/Compiler.h"
#include <cstdint>
static constexpr uint_least32_t
@@ -35,7 +33,7 @@ MakeAlsaVersion(uint_least32_t major, uint_least32_t minor,
* Wrapper for snd_asoundlib_version() which translates the resulting
* string to an integer constructed with MakeAlsaVersion().
*/
gcc_const
[[gnu::const]]
uint_least32_t
GetRuntimeAlsaVersion() noexcept;

View File

@@ -31,7 +31,6 @@
#define CDIO_PARANOIA_HXX
#include "util/ConstBuffer.hxx"
#include "util/Compiler.h"
#include <cdio/version.h>
#include <cdio/paranoia/paranoia.h>
@@ -88,7 +87,7 @@ public:
return std::pair(first, last);
}
gcc_pure
[[gnu::pure]]
bool IsAudioTrack(track_t i) const noexcept {
return cdio_cddap_track_audiop(drv, i);
}
@@ -101,7 +100,7 @@ public:
return std::pair(first, last);
}
gcc_pure
[[gnu::pure]]
unsigned GetTrackCount() const noexcept {
return cdio_cddap_tracks(drv);
}

View File

@@ -31,7 +31,6 @@
#define MD5_HXX
#include "util/StringBuffer.hxx"
#include "util/Compiler.h"
#include <array>
#include <cstdint>
@@ -41,11 +40,11 @@ template<typename T> struct ConstBuffer;
void
GlobalInitMD5() noexcept;
gcc_pure
[[gnu::pure]]
std::array<uint8_t, 16>
MD5(ConstBuffer<void> input) noexcept;
gcc_pure
[[gnu::pure]]
StringBuffer<33>
MD5Hex(ConstBuffer<void> input) noexcept;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016-2018 Max Kellermann <max.kellermann@gmail.com>
* Copyright 2016-2021 Max Kellermann <max.kellermann@gmail.com>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -31,7 +31,6 @@
#define CURL_EASY_HXX
#include "String.hxx"
#include "util/Compiler.h"
#include <curl/curl.h>
@@ -199,7 +198,7 @@ public:
/**
* Returns the response body's size, or -1 if that is unknown.
*/
gcc_pure
[[gnu::pure]]
int64_t GetContentLength() const noexcept {
double value;
return GetInfo(CURLINFO_CONTENT_LENGTH_DOWNLOAD, &value)

View File

@@ -31,6 +31,7 @@
#include "Request.hxx"
#include "event/Loop.hxx"
#include "event/SocketEvent.hxx"
#include "util/Compiler.h"
#include <cassert>
@@ -84,7 +85,7 @@ private:
(flags & SocketEvent::ERROR ? CURL_CSELECT_ERR : 0);
}
gcc_const
[[gnu::const]]
static unsigned CurlPollToFlags(int action) noexcept {
switch (action) {
case CURL_POLL_NONE:
@@ -172,7 +173,7 @@ CurlGlobal::Remove(CurlRequest &r) noexcept
/**
* Find a request by its CURL "easy" handle.
*/
gcc_pure
[[gnu::pure]]
static CurlRequest *
ToRequest(CURL *easy) noexcept
{

View File

@@ -172,7 +172,7 @@ CurlRequest::Done(CURLcode result) noexcept
}
}
gcc_pure
[[gnu::pure]]
static bool
IsResponseBoundaryHeader(StringView s) noexcept
{

View File

@@ -30,9 +30,7 @@
#ifndef CURL_VERSION_HXX
#define CURL_VERSION_HXX
#include "util/Compiler.h"
gcc_const
[[gnu::const]]
bool
IsCurlOlderThan(unsigned version_num) noexcept;

View File

@@ -33,8 +33,6 @@
#ifndef ODBUS_ERROR_HXX
#define ODBUS_ERROR_HXX
#include "util/Compiler.h"
#include <dbus/dbus.h>
namespace ODBus {
@@ -54,7 +52,7 @@ public:
Error(const Error &) = delete;
Error &operator=(const Error &) = delete;
gcc_pure
[[gnu::pure]]
operator bool() const noexcept {
return dbus_error_is_set(&error);
}

View File

@@ -20,8 +20,6 @@
#ifndef MPD_EXPAT_HXX
#define MPD_EXPAT_HXX
#include "util/Compiler.h"
#include <expat.h>
#include <stdexcept>
@@ -80,11 +78,11 @@ public:
void Parse(InputStream &is);
gcc_pure
[[gnu::pure]]
static const char *GetAttribute(const XML_Char **atts,
const char *name) noexcept;
gcc_pure
[[gnu::pure]]
static const char *GetAttributeCase(const XML_Char **atts,
const char *name) noexcept;
};
@@ -117,13 +115,13 @@ public:
parser.CompleteParse();
}
gcc_pure
[[gnu::pure]]
static const char *GetAttribute(const XML_Char **atts,
const char *name) noexcept {
return ExpatParser::GetAttribute(atts, name);
}
gcc_pure
[[gnu::pure]]
static const char *GetAttributeCase(const XML_Char **atts,
const char *name) noexcept {
return ExpatParser::GetAttributeCase(atts, name);

View File

@@ -20,8 +20,6 @@
#ifndef MPD_FFMPEG_BUFFER_HXX
#define MPD_FFMPEG_BUFFER_HXX
#include "util/Compiler.h"
extern "C" {
#include <libavutil/mem.h>
}
@@ -42,7 +40,7 @@ public:
FfmpegBuffer(const FfmpegBuffer &) = delete;
FfmpegBuffer &operator=(const FfmpegBuffer &) = delete;
gcc_malloc
[[gnu::malloc]]
void *Get(size_t min_size) noexcept {
av_fast_malloc(&data, &size, min_size);
return data;

View File

@@ -20,7 +20,6 @@
#ifndef MPD_FFMPEG_IO_CONTEXT_HXX
#define MPD_FFMPEG_IO_CONTEXT_HXX
#include "util/Compiler.h"
#include "Error.hxx"
extern "C" {
@@ -65,12 +64,12 @@ public:
return io_context;
}
gcc_pure
[[gnu::pure]]
auto GetSize() const noexcept {
return avio_size(io_context);
}
gcc_pure
[[gnu::pure]]
bool IsEOF() const noexcept {
return avio_feof(io_context) != 0;
}

View File

@@ -21,7 +21,6 @@
#define MPD_FFMPEG_TIME_HXX
#include "Chrono.hxx"
#include "util/Compiler.h"
extern "C" {
#include <libavutil/avutil.h>
@@ -41,7 +40,7 @@ static constexpr AVRational AV_TIME_BASE_Q{1, AV_TIME_BASE};
/**
* Convert a FFmpeg time stamp to a floating point value (in seconds).
*/
gcc_const
[[gnu::const]]
static inline FloatDuration
FfmpegTimeToDouble(int64_t t, const AVRational time_base) noexcept
{
@@ -64,7 +63,7 @@ RatioToAVRational()
/**
* Convert a FFmpeg time stamp to a #SongTime.
*/
gcc_const
[[gnu::const]]
static inline SongTime
FromFfmpegTime(int64_t t, const AVRational time_base) noexcept
{
@@ -77,7 +76,7 @@ FromFfmpegTime(int64_t t, const AVRational time_base) noexcept
/**
* Convert a FFmpeg time stamp to a #SignedSongTime.
*/
gcc_const
[[gnu::const]]
static inline SignedSongTime
FromFfmpegTimeChecked(int64_t t, const AVRational time_base) noexcept
{
@@ -89,7 +88,7 @@ FromFfmpegTimeChecked(int64_t t, const AVRational time_base) noexcept
/**
* Convert a #SongTime to a FFmpeg time stamp with the given base.
*/
gcc_const
[[gnu::const]]
static inline int64_t
ToFfmpegTime(SongTime t, const AVRational time_base) noexcept
{
@@ -104,7 +103,7 @@ ToFfmpegTime(SongTime t, const AVRational time_base) noexcept
constexpr int64_t
FfmpegTimestampFallback(int64_t t, int64_t fallback)
{
return gcc_likely(t != int64_t(AV_NOPTS_VALUE))
return t != int64_t(AV_NOPTS_VALUE)
? t
: fallback;
}

View File

@@ -31,7 +31,6 @@
#define GCRYPT_HASH_HXX
#include "util/ConstBuffer.hxx"
#include "util/Compiler.h"
#include <gcrypt.h>
@@ -40,7 +39,7 @@
namespace Gcrypt {
template<int algo, size_t size>
gcc_pure
[[gnu::pure]]
auto
Hash(ConstBuffer<void> input) noexcept
{

View File

@@ -31,7 +31,6 @@
#define GCRYPT_MD5_HXX
#include "util/StringBuffer.hxx"
#include "util/Compiler.h"
#include <array>
#include <cstdint>
@@ -40,7 +39,7 @@ template<typename T> struct ConstBuffer;
namespace Gcrypt {
gcc_pure
[[gnu::pure]]
std::array<uint8_t, 16>
MD5(ConstBuffer<void> input) noexcept;

View File

@@ -76,7 +76,7 @@ IcuCollateFinish() noexcept
#endif
gcc_pure
[[gnu::pure]]
int
IcuCollate(std::string_view a, std::string_view b) noexcept
{

View File

@@ -20,8 +20,6 @@
#ifndef MPD_ICU_COLLATE_HXX
#define MPD_ICU_COLLATE_HXX
#include "util/Compiler.h"
#include <string_view>
/**
@@ -33,7 +31,7 @@ IcuCollateInit();
void
IcuCollateFinish() noexcept;
gcc_pure
[[gnu::pure]]
int
IcuCollate(std::string_view a, std::string_view b) noexcept;

View File

@@ -20,7 +20,6 @@
#ifndef MPD_ICU_COMPARE_HXX
#define MPD_ICU_COMPARE_HXX
#include "util/Compiler.h"
#include "util/AllocatedString.hxx"
#include <string_view>
@@ -63,15 +62,15 @@ public:
IcuCompare(IcuCompare &&) = default;
IcuCompare &operator=(IcuCompare &&) = default;
gcc_pure
[[gnu::pure]]
operator bool() const noexcept {
return needle != nullptr;
}
gcc_pure
[[gnu::pure]]
bool operator==(const char *haystack) const noexcept;
gcc_pure
[[gnu::pure]]
bool IsIn(const char *haystack) const noexcept;
};

View File

@@ -20,7 +20,6 @@
#ifndef MPD_ICU_CONVERTER_HXX
#define MPD_ICU_CONVERTER_HXX
#include "util/Compiler.h"
#include "config.h"
#ifdef HAVE_ICU
@@ -84,7 +83,6 @@ public:
*
* Throws std::runtime_error on error.
*/
gcc_nonnull_all
AllocatedString ToUTF8(std::string_view s) const;
/**
@@ -92,7 +90,6 @@ public:
*
* Throws std::runtime_error on error.
*/
gcc_nonnull_all
AllocatedString FromUTF8(std::string_view s) const;
};

View File

@@ -20,8 +20,6 @@
#ifndef MPD_ICU_WIN32_HXX
#define MPD_ICU_WIN32_HXX
#include "util/Compiler.h"
#include <string_view>
class AllocatedString;
@@ -30,14 +28,14 @@ template<typename T> class BasicAllocatedString;
/**
* Throws std::system_error on error.
*/
gcc_pure gcc_nonnull_all
[[gnu::pure]]
AllocatedString
WideCharToMultiByte(unsigned code_page, std::wstring_view src);
/**
* Throws std::system_error on error.
*/
gcc_pure gcc_nonnull_all
[[gnu::pure]]
BasicAllocatedString<wchar_t>
MultiByteToWideChar(unsigned code_page, std::string_view src);

View File

@@ -20,8 +20,6 @@
#ifndef MPD_NFS_BASE_HXX
#define MPD_NFS_BASE_HXX
#include "util/Compiler.h"
/**
* Set the "base" NFS server and export name. This will be the
* default export that will be mounted if a file within this export is
@@ -38,7 +36,7 @@ nfs_set_base(const char *server, const char *export_name) noexcept;
* "path" after the export_name is returned; otherwise, nullptr is
* returned.
*/
gcc_pure
[[gnu::pure]]
const char *
nfs_check_base(const char *server, const char *path) noexcept;

View File

@@ -20,8 +20,6 @@
#ifndef MPD_NFS_CANCELLABLE_HXX
#define MPD_NFS_CANCELLABLE_HXX
#include "util/Compiler.h"
#include <boost/intrusive/list.hpp>
#include <algorithm>
@@ -89,35 +87,35 @@ private:
}
};
gcc_pure
[[gnu::pure]]
iterator Find(reference p) noexcept {
return std::find_if(list.begin(), list.end(), MatchPointer(p));
}
gcc_pure
[[gnu::pure]]
const_iterator Find(const_reference p) const noexcept {
return std::find_if(list.begin(), list.end(), MatchPointer(p));
}
gcc_pure
[[gnu::pure]]
iterator Find(CT &c) noexcept {
return list.iterator_to(c);
}
gcc_pure
[[gnu::pure]]
const_iterator Find(const CT &c) const noexcept {
return list.iterator_to(c);
}
public:
#ifndef NDEBUG
gcc_pure
[[gnu::pure]]
bool IsEmpty() const noexcept {
return std::all_of(list.begin(), list.end(), [](const auto &c) { return c.IsCancelled(); });
}
#endif
gcc_pure
[[gnu::pure]]
bool Contains(const_reference p) const noexcept {
return Find(p) != list.end();
}

View File

@@ -24,7 +24,6 @@
#include "event/SocketEvent.hxx"
#include "event/CoarseTimerEvent.hxx"
#include "event/DeferEvent.hxx"
#include "util/Compiler.h"
#include <string>
#include <list>
@@ -139,7 +138,7 @@ class NfsConnection {
bool mount_finished;
public:
gcc_nonnull_all
[[gnu::nonnull]]
NfsConnection(EventLoop &_loop,
const char *_server, const char *_export_name) noexcept
:socket_event(_loop, BIND_THIS_METHOD(OnSocketReady)),
@@ -157,12 +156,12 @@ public:
return socket_event.GetEventLoop();
}
gcc_pure
[[gnu::pure]]
const char *GetServer() const noexcept {
return server.c_str();
}
gcc_pure
[[gnu::pure]]
const char *GetExportName() const noexcept {
return export_name.c_str();
}

View File

@@ -20,8 +20,6 @@
#ifndef MPD_NFS_GLUE_HXX
#define MPD_NFS_GLUE_HXX
#include "util/Compiler.h"
class EventLoop;
class NfsConnection;
@@ -34,11 +32,11 @@ nfs_finish() noexcept;
/**
* Return the EventLoop that was passed to nfs_init().
*/
gcc_const
[[gnu::const]]
EventLoop &
nfs_get_event_loop() noexcept;
gcc_pure
[[gnu::pure]]
NfsConnection &
nfs_get_connection(const char *server, const char *export_name) noexcept;

View File

@@ -21,7 +21,6 @@
#define MPD_NFS_MANAGER_HXX
#include "Connection.hxx"
#include "util/Compiler.h"
#include "event/IdleEvent.hxx"
#include <boost/intrusive/set.hpp>
@@ -56,15 +55,15 @@ class NfsManager final {
};
struct Compare {
gcc_pure
[[gnu::pure]]
bool operator()(const LookupKey a,
const ManagedConnection &b) const noexcept;
gcc_pure
[[gnu::pure]]
bool operator()(const ManagedConnection &a,
const LookupKey b) const noexcept;
gcc_pure
[[gnu::pure]]
bool operator()(const ManagedConnection &a,
const ManagedConnection &b) const noexcept;
};
@@ -102,7 +101,7 @@ public:
return idle_event.GetEventLoop();
}
gcc_pure
[[gnu::pure]]
NfsConnection &GetConnection(const char *server,
const char *export_name) noexcept;

View File

@@ -59,7 +59,7 @@ public:
return re != nullptr;
}
gcc_pure
[[gnu::pure]]
bool Match(StringView s) const noexcept {
/* we don't need the data written to ovector, but PCRE can
omit internal allocations if we pass a buffer to

View File

@@ -21,7 +21,6 @@
#define _UPNPDIR_HXX_INCLUDED_
#include "Compat.hxx"
#include "util/Compiler.h"
#include <string>
#include <forward_list>
@@ -112,7 +111,7 @@ public:
*/
std::forward_list<std::string> getSearchCapabilities(UpnpClient_Handle handle) const;
gcc_pure
[[gnu::pure]]
std::string GetURI() const noexcept {
return "upnp://" + m_deviceId + "/" + m_serviceType;
}

View File

@@ -20,8 +20,6 @@
#ifndef MPD_FLAC_METADATA_CHAIN_HXX
#define MPD_FLAC_METADATA_CHAIN_HXX
#include "util/Compiler.h"
#include <FLAC/metadata.h>
class InputStream;
@@ -67,12 +65,12 @@ public:
bool ReadOgg(InputStream &is) noexcept;
gcc_pure
[[gnu::pure]]
FLAC__Metadata_ChainStatus GetStatus() const noexcept {
return ::FLAC__metadata_chain_status(chain);
}
gcc_pure
[[gnu::pure]]
const char *GetStatusString() const noexcept {
return FLAC__Metadata_ChainStatusString[GetStatus()];
}