From 672278e5fd83baf76a6ad55ec30aee43c843073f Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 22 Jul 2021 13:36:53 +0200 Subject: [PATCH] util/StringView: use [[gnu::]] attributes --- src/util/StringView.hxx | 28 ++++++++++++++-------------- src/util/WStringView.hxx | 2 +- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/util/StringView.hxx b/src/util/StringView.hxx index 5d782839f..9c594d767 100644 --- a/src/util/StringView.hxx +++ b/src/util/StringView.hxx @@ -1,5 +1,5 @@ /* - * Copyright 2013-2020 Max Kellermann + * Copyright 2013-2021 Max Kellermann * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -103,12 +103,12 @@ struct BasicStringView : ConstBuffer { return {start, size_t(data + size - start)}; } - gcc_pure + [[gnu::pure]] pointer Find(value_type ch) const noexcept { return StringFind(data, ch, this->size); } - gcc_pure + [[gnu::pure]] pointer FindLast(value_type ch) const noexcept { return StringFindLast(data, ch, size); } @@ -118,7 +118,7 @@ struct BasicStringView : ConstBuffer { * character. If the character is not found, then the first * value is the whole string and the second value is nullptr. */ - gcc_pure + [[gnu::pure]] std::pair, BasicStringView> Split(value_type ch) const noexcept { const auto separator = Find(ch); if (separator == nullptr) @@ -132,7 +132,7 @@ struct BasicStringView : ConstBuffer { * character. If the character is not found, then the first * value is the whole string and the second value is nullptr. */ - gcc_pure + [[gnu::pure]] std::pair, BasicStringView> SplitLast(value_type ch) const noexcept { const auto separator = FindLast(ch); if (separator == nullptr) @@ -141,30 +141,30 @@ struct BasicStringView : ConstBuffer { return {{begin(), separator}, {separator + 1, end()}}; } - gcc_pure + [[gnu::pure]] bool StartsWith(BasicStringView needle) const noexcept { return this->size >= needle.size && StringIsEqual(data, needle.data, needle.size); } - gcc_pure + [[gnu::pure]] bool EndsWith(BasicStringView needle) const noexcept { return this->size >= needle.size && StringIsEqual(data + this->size - needle.size, needle.data, needle.size); } - gcc_pure + [[gnu::pure]] bool StartsWith(value_type ch) const noexcept { return !empty() && front() == ch; } - gcc_pure + [[gnu::pure]] bool EndsWith(value_type ch) const noexcept { return !empty() && back() == ch; } - gcc_pure + [[gnu::pure]] int Compare(BasicStringView other) const noexcept { if (size < other.size) { int result = StringCompare(data, other.data, size); @@ -181,26 +181,26 @@ struct BasicStringView : ConstBuffer { return StringCompare(data, other.data, size); } - gcc_pure + [[gnu::pure]] bool Equals(BasicStringView other) const noexcept { return this->size == other.size && StringIsEqual(data, other.data, this->size); } - gcc_pure + [[gnu::pure]] bool StartsWithIgnoreCase(BasicStringView needle) const noexcept { return this->size >= needle.size && StringIsEqualIgnoreCase(data, needle.data, needle.size); } - gcc_pure + [[gnu::pure]] bool EndsWithIgnoreCase(BasicStringView needle) const noexcept { return this->size >= needle.size && StringIsEqualIgnoreCase(data + this->size - needle.size, needle.data, needle.size); } - gcc_pure + [[gnu::pure]] bool EqualsIgnoreCase(BasicStringView other) const noexcept { return this->size == other.size && StringIsEqualIgnoreCase(data, other.data, this->size); diff --git a/src/util/WStringView.hxx b/src/util/WStringView.hxx index 50761f69d..e5feb4a34 100644 --- a/src/util/WStringView.hxx +++ b/src/util/WStringView.hxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013-2017 Max Kellermann + * Copyright 2013-2021 Max Kellermann * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions