Commit 672278e5 authored by Max Kellermann's avatar Max Kellermann Committed by Max Kellermann

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

parent da155f88
/* /*
* 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 * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
...@@ -103,12 +103,12 @@ struct BasicStringView : ConstBuffer<T> { ...@@ -103,12 +103,12 @@ struct BasicStringView : ConstBuffer<T> {
return {start, size_t(data + size - start)}; return {start, size_t(data + size - start)};
} }
gcc_pure [[gnu::pure]]
pointer Find(value_type ch) const noexcept { pointer Find(value_type ch) const noexcept {
return StringFind(data, ch, this->size); return StringFind(data, ch, this->size);
} }
gcc_pure [[gnu::pure]]
pointer FindLast(value_type ch) const noexcept { pointer FindLast(value_type ch) const noexcept {
return StringFindLast(data, ch, size); return StringFindLast(data, ch, size);
} }
...@@ -118,7 +118,7 @@ struct BasicStringView : ConstBuffer<T> { ...@@ -118,7 +118,7 @@ struct BasicStringView : ConstBuffer<T> {
* character. If the character is not found, then the first * character. If the character is not found, then the first
* value is the whole string and the second value is nullptr. * value is the whole string and the second value is nullptr.
*/ */
gcc_pure [[gnu::pure]]
std::pair<BasicStringView<T>, BasicStringView<T>> Split(value_type ch) const noexcept { std::pair<BasicStringView<T>, BasicStringView<T>> Split(value_type ch) const noexcept {
const auto separator = Find(ch); const auto separator = Find(ch);
if (separator == nullptr) if (separator == nullptr)
...@@ -132,7 +132,7 @@ struct BasicStringView : ConstBuffer<T> { ...@@ -132,7 +132,7 @@ struct BasicStringView : ConstBuffer<T> {
* character. If the character is not found, then the first * character. If the character is not found, then the first
* value is the whole string and the second value is nullptr. * value is the whole string and the second value is nullptr.
*/ */
gcc_pure [[gnu::pure]]
std::pair<BasicStringView<T>, BasicStringView<T>> SplitLast(value_type ch) const noexcept { std::pair<BasicStringView<T>, BasicStringView<T>> SplitLast(value_type ch) const noexcept {
const auto separator = FindLast(ch); const auto separator = FindLast(ch);
if (separator == nullptr) if (separator == nullptr)
...@@ -141,30 +141,30 @@ struct BasicStringView : ConstBuffer<T> { ...@@ -141,30 +141,30 @@ struct BasicStringView : ConstBuffer<T> {
return {{begin(), separator}, {separator + 1, end()}}; return {{begin(), separator}, {separator + 1, end()}};
} }
gcc_pure [[gnu::pure]]
bool StartsWith(BasicStringView<T> needle) const noexcept { bool StartsWith(BasicStringView<T> needle) const noexcept {
return this->size >= needle.size && return this->size >= needle.size &&
StringIsEqual(data, needle.data, needle.size); StringIsEqual(data, needle.data, needle.size);
} }
gcc_pure [[gnu::pure]]
bool EndsWith(BasicStringView<T> needle) const noexcept { bool EndsWith(BasicStringView<T> needle) const noexcept {
return this->size >= needle.size && return this->size >= needle.size &&
StringIsEqual(data + this->size - needle.size, StringIsEqual(data + this->size - needle.size,
needle.data, needle.size); needle.data, needle.size);
} }
gcc_pure [[gnu::pure]]
bool StartsWith(value_type ch) const noexcept { bool StartsWith(value_type ch) const noexcept {
return !empty() && front() == ch; return !empty() && front() == ch;
} }
gcc_pure [[gnu::pure]]
bool EndsWith(value_type ch) const noexcept { bool EndsWith(value_type ch) const noexcept {
return !empty() && back() == ch; return !empty() && back() == ch;
} }
gcc_pure [[gnu::pure]]
int Compare(BasicStringView<T> other) const noexcept { int Compare(BasicStringView<T> other) const noexcept {
if (size < other.size) { if (size < other.size) {
int result = StringCompare(data, other.data, size); int result = StringCompare(data, other.data, size);
...@@ -181,26 +181,26 @@ struct BasicStringView : ConstBuffer<T> { ...@@ -181,26 +181,26 @@ struct BasicStringView : ConstBuffer<T> {
return StringCompare(data, other.data, size); return StringCompare(data, other.data, size);
} }
gcc_pure [[gnu::pure]]
bool Equals(BasicStringView<T> other) const noexcept { bool Equals(BasicStringView<T> other) const noexcept {
return this->size == other.size && return this->size == other.size &&
StringIsEqual(data, other.data, this->size); StringIsEqual(data, other.data, this->size);
} }
gcc_pure [[gnu::pure]]
bool StartsWithIgnoreCase(BasicStringView<T> needle) const noexcept { bool StartsWithIgnoreCase(BasicStringView<T> needle) const noexcept {
return this->size >= needle.size && return this->size >= needle.size &&
StringIsEqualIgnoreCase(data, needle.data, needle.size); StringIsEqualIgnoreCase(data, needle.data, needle.size);
} }
gcc_pure [[gnu::pure]]
bool EndsWithIgnoreCase(BasicStringView<T> needle) const noexcept { bool EndsWithIgnoreCase(BasicStringView<T> needle) const noexcept {
return this->size >= needle.size && return this->size >= needle.size &&
StringIsEqualIgnoreCase(data + this->size - needle.size, StringIsEqualIgnoreCase(data + this->size - needle.size,
needle.data, needle.size); needle.data, needle.size);
} }
gcc_pure [[gnu::pure]]
bool EqualsIgnoreCase(BasicStringView<T> other) const noexcept { bool EqualsIgnoreCase(BasicStringView<T> other) const noexcept {
return this->size == other.size && return this->size == other.size &&
StringIsEqualIgnoreCase(data, other.data, this->size); StringIsEqualIgnoreCase(data, other.data, this->size);
......
/* /*
* Copyright (C) 2013-2017 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 * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment