util/PeakBuffer, ...: use [[gnu::]] attributes

This commit is contained in:
Max Kellermann 2022-04-26 20:19:31 +02:00
parent ce88dee14d
commit a742e1fc71
11 changed files with 20 additions and 28 deletions

View File

@ -41,7 +41,7 @@
* Determine whether two strings are equal, ignoring case for ASCII * Determine whether two strings are equal, ignoring case for ASCII
* letters. * letters.
*/ */
gcc_pure gcc_nonnull_all [[gnu::pure]] [[gnu::nonnull]]
static inline bool static inline bool
StringEqualsCaseASCII(const char *a, const char *b) noexcept StringEqualsCaseASCII(const char *a, const char *b) noexcept
{ {
@ -56,7 +56,7 @@ StringEqualsCaseASCII(const char *a, const char *b) noexcept
return strcasecmp(a, b) == 0; return strcasecmp(a, b) == 0;
} }
gcc_pure gcc_nonnull_all [[gnu::pure]] [[gnu::nonnull]]
static inline bool static inline bool
StringEqualsCaseASCII(const char *a, const char *b, size_t n) noexcept StringEqualsCaseASCII(const char *a, const char *b, size_t n) noexcept
{ {
@ -71,7 +71,7 @@ StringEqualsCaseASCII(const char *a, const char *b, size_t n) noexcept
return strncasecmp(a, b, n) == 0; return strncasecmp(a, b, n) == 0;
} }
gcc_pure gcc_nonnull_all [[gnu::pure]] [[gnu::nonnull]]
static inline bool static inline bool
StringStartsWithCaseASCII(const char *haystack, StringStartsWithCaseASCII(const char *haystack,
std::string_view needle) noexcept std::string_view needle) noexcept
@ -79,7 +79,7 @@ StringStartsWithCaseASCII(const char *haystack,
return StringEqualsCaseASCII(haystack, needle.data(), needle.length()); return StringEqualsCaseASCII(haystack, needle.data(), needle.length());
} }
gcc_pure gcc_nonnull_all [[gnu::pure]] [[gnu::nonnull]]
static inline const char * static inline const char *
StringAfterPrefixCaseASCII(const char *haystack, StringAfterPrefixCaseASCII(const char *haystack,
std::string_view needle) noexcept std::string_view needle) noexcept

View File

@ -29,14 +29,15 @@ class AllocatedString;
/** /**
* Format into an #AllocatedString. * Format into an #AllocatedString.
*/ */
gcc_nonnull_all [[gnu::nonnull]]
AllocatedString AllocatedString
FormatStringV(const char *fmt, std::va_list args) noexcept; FormatStringV(const char *fmt, std::va_list args) noexcept;
/** /**
* Format into an #AllocatedString. * Format into an #AllocatedString.
*/ */
gcc_nonnull(1) gcc_printf(1,2) [[gnu::nonnull(1)]]
gcc_printf(1,2)
AllocatedString AllocatedString
FormatString(const char *fmt, ...) noexcept; FormatString(const char *fmt, ...) noexcept;

View File

@ -28,7 +28,6 @@
*/ */
#include "HugeAllocator.hxx" #include "HugeAllocator.hxx"
#include "Compiler.h"
#include <new> #include <new>
@ -44,7 +43,7 @@
/** /**
* Round up the parameter, make it page-aligned. * Round up the parameter, make it page-aligned.
*/ */
gcc_const [[gnu::const]]
static size_t static size_t
AlignToPageSize(size_t size) noexcept AlignToPageSize(size_t size) noexcept
{ {

View File

@ -20,8 +20,6 @@
#ifndef MPD_PEAK_BUFFER_HXX #ifndef MPD_PEAK_BUFFER_HXX
#define MPD_PEAK_BUFFER_HXX #define MPD_PEAK_BUFFER_HXX
#include "Compiler.h"
#include <cstddef> #include <cstddef>
template<typename T> struct WritableBuffer; template<typename T> struct WritableBuffer;
@ -59,10 +57,10 @@ public:
return normal_size + peak_size; return normal_size + peak_size;
} }
gcc_pure [[gnu::pure]]
bool empty() const noexcept; bool empty() const noexcept;
gcc_pure [[gnu::pure]]
WritableBuffer<void> Read() const noexcept; WritableBuffer<void> Read() const noexcept;
void Consume(std::size_t length) noexcept; void Consume(std::size_t length) noexcept;

View File

@ -83,7 +83,7 @@ public:
* Get the buffer, and guarantee a minimum size. This buffer * Get the buffer, and guarantee a minimum size. This buffer
* becomes invalid with the next Get() call. * becomes invalid with the next Get() call.
*/ */
gcc_malloc gcc_returns_nonnull [[gnu::malloc]] [[gnu::returns_nonnull]]
T *Get(size_t size) { T *Get(size_t size) {
if (gcc_unlikely(size > capacity)) { if (gcc_unlikely(size > capacity)) {
/* too small: grow */ /* too small: grow */

View File

@ -21,7 +21,6 @@
#define MPD_SLICE_BUFFER_HXX #define MPD_SLICE_BUFFER_HXX
#include "HugeAllocator.hxx" #include "HugeAllocator.hxx"
#include "Compiler.h"
#include <cassert> #include <cassert>
#include <cstddef> #include <cstddef>

View File

@ -30,8 +30,6 @@
#ifndef URI_QUERY_PARSER_HXX #ifndef URI_QUERY_PARSER_HXX
#define URI_QUERY_PARSER_HXX #define URI_QUERY_PARSER_HXX
#include "Compiler.h"
struct StringView; struct StringView;
/** /**
@ -41,7 +39,7 @@ struct StringView;
* @return the raw value (pointing into the #query_string parameter) * @return the raw value (pointing into the #query_string parameter)
* or nullptr if the parameter does not exist * or nullptr if the parameter does not exist
*/ */
gcc_pure [[gnu::pure]]
StringView StringView
UriFindRawQueryParameter(StringView query_string, StringView name) noexcept; UriFindRawQueryParameter(StringView query_string, StringView name) noexcept;

View File

@ -31,6 +31,7 @@
#include "UriExtract.hxx" #include "UriExtract.hxx"
#include "StringAPI.hxx" #include "StringAPI.hxx"
#include "StringCompare.hxx" #include "StringCompare.hxx"
#include "Compiler.h"
#include <cassert> #include <cassert>

View File

@ -30,8 +30,6 @@
#ifndef URI_RELATIVE_HXX #ifndef URI_RELATIVE_HXX
#define URI_RELATIVE_HXX #define URI_RELATIVE_HXX
#include "Compiler.h"
#include <string> #include <string>
#include <string_view> #include <string_view>
@ -40,11 +38,11 @@
* specified by #parent. If the strings are equal, the function * specified by #parent. If the strings are equal, the function
* returns false. * returns false.
*/ */
gcc_pure gcc_nonnull_all [[gnu::pure]] [[gnu::nonnull]]
bool bool
uri_is_child(const char *parent, const char *child) noexcept; uri_is_child(const char *parent, const char *child) noexcept;
gcc_pure gcc_nonnull_all [[gnu::pure]] [[gnu::nonnull]]
bool bool
uri_is_child_or_same(const char *parent, const char *child) noexcept; uri_is_child_or_same(const char *parent, const char *child) noexcept;
@ -52,11 +50,11 @@ uri_is_child_or_same(const char *parent, const char *child) noexcept;
* Translate the given URI in the context of #base. For example, * Translate the given URI in the context of #base. For example,
* uri_apply_base("foo", "http://bar/a/")=="http://bar/a/foo". * uri_apply_base("foo", "http://bar/a/")=="http://bar/a/foo".
*/ */
gcc_pure [[gnu::pure]]
std::string std::string
uri_apply_base(std::string_view uri, std::string_view base) noexcept; uri_apply_base(std::string_view uri, std::string_view base) noexcept;
gcc_pure [[gnu::pure]]
std::string std::string
uri_apply_relative(std::string_view relative_uri, uri_apply_relative(std::string_view relative_uri,
std::string_view base_uri) noexcept; std::string_view base_uri) noexcept;

View File

@ -70,7 +70,7 @@ uri_safe_local(const char *uri) noexcept
} }
} }
gcc_pure [[gnu::pure]]
static const char * static const char *
SkipUriScheme(const char *uri) noexcept SkipUriScheme(const char *uri) noexcept
{ {

View File

@ -30,8 +30,6 @@
#ifndef MPD_VAR_SIZE_HXX #ifndef MPD_VAR_SIZE_HXX
#define MPD_VAR_SIZE_HXX #define MPD_VAR_SIZE_HXX
#include "Compiler.h"
#include <type_traits> #include <type_traits>
#include <utility> #include <utility>
#include <new> #include <new>
@ -49,7 +47,7 @@
* #T * #T
*/ */
template<class T, typename... Args> template<class T, typename... Args>
gcc_malloc gcc_returns_nonnull [[gnu::malloc]] [[gnu::returns_nonnull]]
T * T *
NewVarSize(size_t declared_tail_size, size_t real_tail_size, Args&&... args) NewVarSize(size_t declared_tail_size, size_t real_tail_size, Args&&... args)
{ {
@ -71,7 +69,7 @@ NewVarSize(size_t declared_tail_size, size_t real_tail_size, Args&&... args)
} }
template<typename T> template<typename T>
gcc_nonnull_all [[gnu::nonnull]]
void void
DeleteVarSize(T *instance) DeleteVarSize(T *instance)
{ {