util/StringCompare: use [[gnu::]] attributes

This commit is contained in:
Max Kellermann 2021-07-22 13:35:36 +02:00 committed by Max Kellermann
parent 4026ef63b6
commit da155f8822
2 changed files with 24 additions and 26 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright 2013-2020 Max Kellermann <max.kellermann@gmail.com>
* Copyright 2013-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
@ -32,7 +32,6 @@
#include "StringView.hxx"
#include "StringAPI.hxx"
#include "Compiler.h"
#ifdef _UNICODE
#include "WStringCompare.hxx"
@ -40,14 +39,14 @@
#include <string_view>
gcc_pure gcc_nonnull_all
[[gnu::pure]] [[gnu::nonnull]]
static inline bool
StringIsEmpty(const char *string) noexcept
{
return *string == 0;
}
gcc_pure
[[gnu::pure]]
static inline bool
StringIsEqual(std::string_view a, std::string_view b) noexcept
{
@ -55,7 +54,7 @@ StringIsEqual(std::string_view a, std::string_view b) noexcept
StringIsEqual(a.data(), b.data(), b.size());
}
gcc_pure
[[gnu::pure]]
static inline bool
StringIsEqualIgnoreCase(std::string_view a, std::string_view b) noexcept
{
@ -63,18 +62,18 @@ StringIsEqualIgnoreCase(std::string_view a, std::string_view b) noexcept
StringIsEqualIgnoreCase(a.data(), b.data(), b.size());
}
gcc_pure gcc_nonnull_all
[[gnu::pure]] [[gnu::nonnull]]
static inline bool
StringStartsWith(const char *haystack, StringView needle) noexcept
{
return StringIsEqual(haystack, needle.data, needle.size);
}
gcc_pure gcc_nonnull_all
[[gnu::pure]] [[gnu::nonnull]]
bool
StringEndsWith(const char *haystack, const char *needle) noexcept;
gcc_pure gcc_nonnull_all
[[gnu::pure]] [[gnu::nonnull]]
bool
StringEndsWithIgnoreCase(const char *haystack, const char *needle) noexcept;
@ -83,7 +82,7 @@ StringEndsWithIgnoreCase(const char *haystack, const char *needle) noexcept;
* does not begin with the specified prefix, this function returns
* nullptr.
*/
gcc_pure gcc_nonnull_all
[[gnu::pure]] [[gnu::nonnull]]
static inline const char *
StringAfterPrefix(const char *haystack, StringView needle) noexcept
{
@ -92,14 +91,14 @@ StringAfterPrefix(const char *haystack, StringView needle) noexcept
: nullptr;
}
gcc_pure gcc_nonnull_all
[[gnu::pure]] [[gnu::nonnull]]
static inline bool
StringStartsWithIgnoreCase(const char *haystack, StringView needle) noexcept
{
return StringIsEqualIgnoreCase(haystack, needle.data, needle.size);
}
gcc_pure
[[gnu::pure]]
static inline bool
StringStartsWithIgnoreCase(StringView haystack, StringView needle) noexcept
{
@ -113,7 +112,7 @@ StringStartsWithIgnoreCase(StringView haystack, StringView needle) noexcept
* nullptr.
* This function is case-independent.
*/
gcc_pure gcc_nonnull_all
[[gnu::pure]] [[gnu::nonnull]]
static inline const char *
StringAfterPrefixIgnoreCase(const char *haystack, StringView needle) noexcept
{
@ -122,7 +121,7 @@ StringAfterPrefixIgnoreCase(const char *haystack, StringView needle) noexcept
: nullptr;
}
gcc_pure
[[gnu::pure]]
static inline StringView
StringAfterPrefixIgnoreCase(StringView haystack,
StringView needle) noexcept
@ -136,7 +135,7 @@ StringAfterPrefixIgnoreCase(StringView haystack,
* Check if the given string ends with the specified suffix. If yes,
* returns the position of the suffix, and nullptr otherwise.
*/
gcc_pure gcc_nonnull_all
[[gnu::pure]] [[gnu::nonnull]]
const char *
FindStringSuffix(const char *p, const char *suffix) noexcept;

View File

@ -1,5 +1,5 @@
/*
* Copyright 2013-2020 Max Kellermann <max.kellermann@gmail.com>
* Copyright 2013-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
@ -32,20 +32,19 @@
#include "WStringView.hxx"
#include "WStringAPI.hxx"
#include "Compiler.h"
#include <string_view>
#include <wchar.h>
gcc_pure gcc_nonnull_all
[[gnu::pure]] [[gnu::nonnull]]
static inline bool
StringIsEmpty(const wchar_t *string) noexcept
{
return *string == 0;
}
gcc_pure
[[gnu::pure]]
static inline bool
StringIsEqual(std::wstring_view a, std::wstring_view b) noexcept
{
@ -53,7 +52,7 @@ StringIsEqual(std::wstring_view a, std::wstring_view b) noexcept
StringIsEqual(a.data(), b.data(), b.size());
}
gcc_pure
[[gnu::pure]]
static inline bool
StringIsEqualIgnoreCase(std::wstring_view a, std::wstring_view b) noexcept
{
@ -61,18 +60,18 @@ StringIsEqualIgnoreCase(std::wstring_view a, std::wstring_view b) noexcept
StringIsEqualIgnoreCase(a.data(), b.data(), b.size());
}
gcc_pure gcc_nonnull_all
[[gnu::pure]] [[gnu::nonnull]]
static inline bool
StringStartsWith(const wchar_t *haystack, WStringView needle) noexcept
{
return StringIsEqual(haystack, needle.data, needle.size);
}
gcc_pure gcc_nonnull_all
[[gnu::pure]] [[gnu::nonnull]]
bool
StringEndsWith(const wchar_t *haystack, const wchar_t *needle) noexcept;
gcc_pure gcc_nonnull_all
[[gnu::pure]] [[gnu::nonnull]]
bool
StringEndsWithIgnoreCase(const wchar_t *haystack,
const wchar_t *needle) noexcept;
@ -82,7 +81,7 @@ StringEndsWithIgnoreCase(const wchar_t *haystack,
* does not begin with the specified prefix, this function returns
* nullptr.
*/
gcc_pure gcc_nonnull_all
[[gnu::pure]] [[gnu::nonnull]]
static inline const wchar_t *
StringAfterPrefix(const wchar_t *haystack, WStringView needle) noexcept
{
@ -91,7 +90,7 @@ StringAfterPrefix(const wchar_t *haystack, WStringView needle) noexcept
: nullptr;
}
gcc_pure gcc_nonnull_all
[[gnu::pure]] [[gnu::nonnull]]
static inline bool
StringStartsWithIgnoreCase(const wchar_t *haystack,
WStringView needle) noexcept
@ -105,7 +104,7 @@ StringStartsWithIgnoreCase(const wchar_t *haystack,
* nullptr.
* This function is case-independent.
*/
gcc_pure gcc_nonnull_all
[[gnu::pure]] [[gnu::nonnull]]
static inline const wchar_t *
StringAfterPrefixIgnoreCase(const wchar_t *haystack, WStringView needle) noexcept
{
@ -118,7 +117,7 @@ StringAfterPrefixIgnoreCase(const wchar_t *haystack, WStringView needle) noexcep
* Check if the given string ends with the specified suffix. If yes,
* returns the position of the suffix, and nullptr otherwise.
*/
gcc_pure gcc_nonnull_all
[[gnu::pure]] [[gnu::nonnull]]
const wchar_t *
FindStringSuffix(const wchar_t *p, const wchar_t *suffix) noexcept;