perf(string): add NODISCARD tag to some functions

This commit is contained in:
Redstone1024 2024-09-21 15:54:01 +08:00
parent d137170ccb
commit 00838c2e35
2 changed files with 40 additions and 40 deletions

View File

@ -97,7 +97,7 @@ struct TCString
} }
/** @return The length of a given string. The maximum length is the buffer size. */ /** @return The length of a given string. The maximum length is the buffer size. */
FORCEINLINE static size_t Length(const CharType* InString, size_t SourceSize) NODISCARD FORCEINLINE static size_t Length(const CharType* InString, size_t SourceSize)
{ {
checkf(InString, "Read access violation. InString must not be nullptr."); checkf(InString, "Read access violation. InString must not be nullptr.");
@ -126,7 +126,7 @@ struct TCString
} }
/** Compares two strings. The size is used only for buffer safety not for comparison. */ /** Compares two strings. The size is used only for buffer safety not for comparison. */
FORCEINLINE static strong_ordering Compare(const CharType* LHS, size_t LHSSize, const CharType* RHS, size_t RHSSize) NODISCARD FORCEINLINE static strong_ordering Compare(const CharType* LHS, size_t LHSSize, const CharType* RHS, size_t RHSSize)
{ {
checkf(LHS && RHS, "Read access violation. LHS and RHS must not be nullptr."); checkf(LHS && RHS, "Read access violation. LHS and RHS must not be nullptr.");
@ -159,7 +159,7 @@ struct TCString
/** Finds the first or last occurrence of a character that satisfies the predicate. The terminating null character is considered to be a part of the string. The size is used only for buffer safety. */ /** Finds the first or last occurrence of a character that satisfies the predicate. The terminating null character is considered to be a part of the string. The size is used only for buffer safety. */
template <CPredicate<CharType> F> template <CPredicate<CharType> F>
FORCEINLINE static const CharType* Find(const CharType* InString, size_t BufferSize, F&& InPredicate, ESearchDirection SearchDirection = ESearchDirection::FromStart) NODISCARD FORCEINLINE static const CharType* Find(const CharType* InString, size_t BufferSize, F&& InPredicate, ESearchDirection SearchDirection = ESearchDirection::FromStart)
{ {
checkf(InString, "Read access violation. InString must not be nullptr."); checkf(InString, "Read access violation. InString must not be nullptr.");
@ -199,7 +199,7 @@ struct TCString
/** Finds the first or last occurrence of a character that satisfies the predicate. The terminating null character is considered to be a part of the string. The size is used only for buffer safety. */ /** Finds the first or last occurrence of a character that satisfies the predicate. The terminating null character is considered to be a part of the string. The size is used only for buffer safety. */
template <CPredicate<CharType> F> template <CPredicate<CharType> F>
FORCEINLINE static CharType* Find( CharType* InString, size_t BufferSize, F&& InPredicate, ESearchDirection SearchDirection = ESearchDirection::FromStart) NODISCARD FORCEINLINE static CharType* Find( CharType* InString, size_t BufferSize, F&& InPredicate, ESearchDirection SearchDirection = ESearchDirection::FromStart)
{ {
checkf(InString, "Read access violation. InString must not be nullptr."); checkf(InString, "Read access violation. InString must not be nullptr.");
@ -211,7 +211,7 @@ struct TCString
} }
/** Finds the first or last occurrence of a character. The terminating null character is considered to be a part of the string. The size is used only for buffer safety. */ /** Finds the first or last occurrence of a character. The terminating null character is considered to be a part of the string. The size is used only for buffer safety. */
FORCEINLINE static const CharType* FindChar(const CharType* InString, size_t BufferSize, CharType Character, ESearchDirection SearchDirection = ESearchDirection::FromStart) NODISCARD FORCEINLINE static const CharType* FindChar(const CharType* InString, size_t BufferSize, CharType Character, ESearchDirection SearchDirection = ESearchDirection::FromStart)
{ {
checkf(InString, "Read access violation. InString must not be nullptr."); checkf(InString, "Read access violation. InString must not be nullptr.");
@ -233,7 +233,7 @@ struct TCString
} }
/** Finds the first or last occurrence of a character. The terminating null character is considered to be a part of the string. The size is used only for buffer safety. */ /** Finds the first or last occurrence of a character. The terminating null character is considered to be a part of the string. The size is used only for buffer safety. */
FORCEINLINE static CharType* FindChar( CharType* InString, size_t BufferSize, CharType Character, ESearchDirection SearchDirection = ESearchDirection::FromStart) NODISCARD FORCEINLINE static CharType* FindChar( CharType* InString, size_t BufferSize, CharType Character, ESearchDirection SearchDirection = ESearchDirection::FromStart)
{ {
checkf(InString, "Read access violation. InString must not be nullptr."); checkf(InString, "Read access violation. InString must not be nullptr.");
@ -245,7 +245,7 @@ struct TCString
} }
/** Finds the first or last occurrence of a character in a charset. The size is used only for buffer safety. */ /** Finds the first or last occurrence of a character in a charset. The size is used only for buffer safety. */
FORCEINLINE static const CharType* FindChar(const CharType* InString, size_t BufferSize, const CharType* Charset, size_t CharsetSize, ESearchDirection SearchDirection = ESearchDirection::FromStart) NODISCARD FORCEINLINE static const CharType* FindChar(const CharType* InString, size_t BufferSize, const CharType* Charset, size_t CharsetSize, ESearchDirection SearchDirection = ESearchDirection::FromStart)
{ {
checkf(InString && Charset, "Read access violation. InString and Charset must not be nullptr."); checkf(InString && Charset, "Read access violation. InString and Charset must not be nullptr.");
@ -276,7 +276,7 @@ struct TCString
} }
/** Finds the first or last occurrence of a character in a charset. The size is used only for buffer safety. */ /** Finds the first or last occurrence of a character in a charset. The size is used only for buffer safety. */
FORCEINLINE static CharType* FindChar( CharType* InString, size_t BufferSize, const CharType* Charset, size_t CharsetSize, ESearchDirection SearchDirection = ESearchDirection::FromStart) NODISCARD FORCEINLINE static CharType* FindChar( CharType* InString, size_t BufferSize, const CharType* Charset, size_t CharsetSize, ESearchDirection SearchDirection = ESearchDirection::FromStart)
{ {
checkf(InString && Charset, "Read access violation. InString and Charset must not be nullptr."); checkf(InString && Charset, "Read access violation. InString and Charset must not be nullptr.");
@ -288,7 +288,7 @@ struct TCString
} }
/** Finds the first or last occurrence of a character that is not the given character. The terminating null character is considered to be a part of the string. The size is used only for buffer safety. */ /** Finds the first or last occurrence of a character that is not the given character. The terminating null character is considered to be a part of the string. The size is used only for buffer safety. */
FORCEINLINE static const CharType* FindNotChar(const CharType* InString, size_t BufferSize, CharType Character, ESearchDirection SearchDirection = ESearchDirection::FromStart) NODISCARD FORCEINLINE static const CharType* FindNotChar(const CharType* InString, size_t BufferSize, CharType Character, ESearchDirection SearchDirection = ESearchDirection::FromStart)
{ {
checkf(InString, "Read access violation. InString must not be nullptr."); checkf(InString, "Read access violation. InString must not be nullptr.");
@ -317,7 +317,7 @@ struct TCString
} }
/** Finds the first or last occurrence of a character that is not the given character. The terminating null character is considered to be a part of the string. The size is used only for buffer safety. */ /** Finds the first or last occurrence of a character that is not the given character. The terminating null character is considered to be a part of the string. The size is used only for buffer safety. */
FORCEINLINE static CharType* FindNotChar( CharType* InString, size_t BufferSize, CharType Character, ESearchDirection SearchDirection = ESearchDirection::FromStart) NODISCARD FORCEINLINE static CharType* FindNotChar( CharType* InString, size_t BufferSize, CharType Character, ESearchDirection SearchDirection = ESearchDirection::FromStart)
{ {
checkf(InString, "Read access violation. InString must not be nullptr."); checkf(InString, "Read access violation. InString must not be nullptr.");
@ -329,7 +329,7 @@ struct TCString
} }
/** Finds the first or last occurrence of a character that is not in the given charset. The size is used only for buffer safety. */ /** Finds the first or last occurrence of a character that is not in the given charset. The size is used only for buffer safety. */
FORCEINLINE static const CharType* FindNotChar(const CharType* InString, size_t BufferSize, const CharType* Charset, size_t CharsetSize, ESearchDirection SearchDirection = ESearchDirection::FromStart) NODISCARD FORCEINLINE static const CharType* FindNotChar(const CharType* InString, size_t BufferSize, const CharType* Charset, size_t CharsetSize, ESearchDirection SearchDirection = ESearchDirection::FromStart)
{ {
checkf(InString && Charset, "Read access violation. InString and Charset must not be nullptr."); checkf(InString && Charset, "Read access violation. InString and Charset must not be nullptr.");
@ -353,7 +353,7 @@ struct TCString
} }
/** Finds the first or last occurrence of a character that is not in the given charset. The size is used only for buffer safety. */ /** Finds the first or last occurrence of a character that is not in the given charset. The size is used only for buffer safety. */
FORCEINLINE static CharType* FindNotChar( CharType* InString, size_t BufferSize, const CharType* Charset, size_t CharsetSize, ESearchDirection SearchDirection = ESearchDirection::FromStart) NODISCARD FORCEINLINE static CharType* FindNotChar( CharType* InString, size_t BufferSize, const CharType* Charset, size_t CharsetSize, ESearchDirection SearchDirection = ESearchDirection::FromStart)
{ {
checkf(InString && Charset, "Read access violation. InString and Charset must not be nullptr."); checkf(InString && Charset, "Read access violation. InString and Charset must not be nullptr.");
@ -365,7 +365,7 @@ struct TCString
} }
/** Finds the first or last occurrence of a substring. The size is used only for buffer safety. */ /** Finds the first or last occurrence of a substring. The size is used only for buffer safety. */
FORCEINLINE static const CharType* FindString(const CharType* InString, size_t BufferSize, const CharType* Substring, size_t SubstringSize, ESearchDirection SearchDirection = ESearchDirection::FromStart) NODISCARD FORCEINLINE static const CharType* FindString(const CharType* InString, size_t BufferSize, const CharType* Substring, size_t SubstringSize, ESearchDirection SearchDirection = ESearchDirection::FromStart)
{ {
checkf(InString && Substring, "Read access violation. InString and Substring must not be nullptr."); checkf(InString && Substring, "Read access violation. InString and Substring must not be nullptr.");
@ -421,7 +421,7 @@ struct TCString
} }
/** Finds the first or last occurrence of a substring. The size is used only for buffer safety. */ /** Finds the first or last occurrence of a substring. The size is used only for buffer safety. */
FORCEINLINE static CharType* FindString( CharType* InString, size_t BufferSize, const CharType* Substring, size_t SubstringSize, ESearchDirection SearchDirection = ESearchDirection::FromStart) NODISCARD FORCEINLINE static CharType* FindString( CharType* InString, size_t BufferSize, const CharType* Substring, size_t SubstringSize, ESearchDirection SearchDirection = ESearchDirection::FromStart)
{ {
checkf(InString && Substring, "Read access violation. InString and Substring must not be nullptr."); checkf(InString && Substring, "Read access violation. InString and Substring must not be nullptr.");

View File

@ -22,36 +22,36 @@ struct TLiteral;
template <> template <>
struct TLiteral<char> struct TLiteral<char>
{ {
FORCEINLINE static constexpr const char Select(const char X, const wchar_t , const char8_t , const char16_t , const char32_t ) { return X; } NODISCARD FORCEINLINE static constexpr const char Select(const char X, const wchar_t , const char8_t , const char16_t , const char32_t ) { return X; }
FORCEINLINE static constexpr const char* Select(const char* X, const wchar_t*, const char8_t*, const char16_t*, const char32_t*) { return X; } NODISCARD FORCEINLINE static constexpr const char* Select(const char* X, const wchar_t*, const char8_t*, const char16_t*, const char32_t*) { return X; }
}; };
template <> template <>
struct TLiteral<wchar_t> struct TLiteral<wchar_t>
{ {
FORCEINLINE static constexpr const wchar_t Select(const char , const wchar_t X, const char8_t , const char16_t , const char32_t ) { return X; } NODISCARD FORCEINLINE static constexpr const wchar_t Select(const char , const wchar_t X, const char8_t , const char16_t , const char32_t ) { return X; }
FORCEINLINE static constexpr const wchar_t* Select(const char*, const wchar_t* X, const char8_t*, const char16_t*, const char32_t*) { return X; } NODISCARD FORCEINLINE static constexpr const wchar_t* Select(const char*, const wchar_t* X, const char8_t*, const char16_t*, const char32_t*) { return X; }
}; };
template <> template <>
struct TLiteral<char8_t> struct TLiteral<char8_t>
{ {
FORCEINLINE static constexpr const char8_t Select(const char , const wchar_t , const char8_t X, const char16_t , const char32_t ) { return X; } NODISCARD FORCEINLINE static constexpr const char8_t Select(const char , const wchar_t , const char8_t X, const char16_t , const char32_t ) { return X; }
FORCEINLINE static constexpr const char8_t* Select(const char*, const wchar_t*, const char8_t* X, const char16_t*, const char32_t*) { return X; } NODISCARD FORCEINLINE static constexpr const char8_t* Select(const char*, const wchar_t*, const char8_t* X, const char16_t*, const char32_t*) { return X; }
}; };
template <> template <>
struct TLiteral<char16_t> struct TLiteral<char16_t>
{ {
FORCEINLINE static constexpr const char16_t Select(const char , const wchar_t , const char8_t , const char16_t X, const char32_t ) { return X; } NODISCARD FORCEINLINE static constexpr const char16_t Select(const char , const wchar_t , const char8_t , const char16_t X, const char32_t ) { return X; }
FORCEINLINE static constexpr const char16_t* Select(const char*, const wchar_t*, const char8_t*, const char16_t* X, const char32_t*) { return X; } NODISCARD FORCEINLINE static constexpr const char16_t* Select(const char*, const wchar_t*, const char8_t*, const char16_t* X, const char32_t*) { return X; }
}; };
template <> template <>
struct TLiteral<char32_t> struct TLiteral<char32_t>
{ {
FORCEINLINE static constexpr const char32_t Select(const char , const wchar_t , const char8_t , const char16_t , const char32_t X) { return X; } NODISCARD FORCEINLINE static constexpr const char32_t Select(const char , const wchar_t , const char8_t , const char16_t , const char32_t X) { return X; }
FORCEINLINE static constexpr const char32_t* Select(const char*, const wchar_t*, const char8_t*, const char16_t*, const char32_t* X) { return X; } NODISCARD FORCEINLINE static constexpr const char32_t* Select(const char*, const wchar_t*, const char8_t*, const char16_t*, const char32_t* X) { return X; }
}; };
NAMESPACE_PRIVATE_END NAMESPACE_PRIVATE_END
@ -67,7 +67,7 @@ struct TChar
inline static constexpr CharType NONE = CharType(-1); inline static constexpr CharType NONE = CharType(-1);
FORCEINLINE static constexpr bool IsAlnum(CharType InChar) NODISCARD FORCEINLINE static constexpr bool IsAlnum(CharType InChar)
{ {
if constexpr (CSameAs<CharType, char>) if constexpr (CSameAs<CharType, char>)
{ {
@ -83,7 +83,7 @@ struct TChar
} }
} }
FORCEINLINE static constexpr bool IsAlpha(CharType InChar) NODISCARD FORCEINLINE static constexpr bool IsAlpha(CharType InChar)
{ {
if constexpr (CSameAs<CharType, char>) if constexpr (CSameAs<CharType, char>)
{ {
@ -111,7 +111,7 @@ struct TChar
} }
} }
FORCEINLINE static constexpr bool IsLower(CharType InChar) NODISCARD FORCEINLINE static constexpr bool IsLower(CharType InChar)
{ {
if constexpr (CSameAs<CharType, char>) if constexpr (CSameAs<CharType, char>)
{ {
@ -137,7 +137,7 @@ struct TChar
} }
} }
FORCEINLINE static constexpr bool IsUpper(CharType InChar) NODISCARD FORCEINLINE static constexpr bool IsUpper(CharType InChar)
{ {
if constexpr (CSameAs<CharType, char>) if constexpr (CSameAs<CharType, char>)
{ {
@ -163,13 +163,13 @@ struct TChar
} }
} }
FORCEINLINE static constexpr bool IsDigit(CharType InChar) NODISCARD FORCEINLINE static constexpr bool IsDigit(CharType InChar)
{ {
/* <U0030>..<U0039>; */ /* <U0030>..<U0039>; */
return (InChar >= LITERAL(CharType, '0') && InChar <= LITERAL(CharType, '9')); return (InChar >= LITERAL(CharType, '0') && InChar <= LITERAL(CharType, '9'));
} }
FORCEINLINE static constexpr bool IsDigit(CharType InChar, int Base) NODISCARD FORCEINLINE static constexpr bool IsDigit(CharType InChar, int Base)
{ {
checkf(Base >= 2 && Base <= 36, TEXT("Base must be in the range [2, 36].")); checkf(Base >= 2 && Base <= 36, TEXT("Base must be in the range [2, 36]."));
@ -180,7 +180,7 @@ struct TChar
(InChar >= LITERAL(CharType, 'A') && InChar < LITERAL(CharType, 'A') + Base - 10); (InChar >= LITERAL(CharType, 'A') && InChar < LITERAL(CharType, 'A') + Base - 10);
} }
FORCEINLINE static constexpr bool IsCntrl(CharType InChar) NODISCARD FORCEINLINE static constexpr bool IsCntrl(CharType InChar)
{ {
if constexpr (CSameAs<CharType, char>) if constexpr (CSameAs<CharType, char>)
{ {
@ -217,7 +217,7 @@ struct TChar
} }
} }
FORCEINLINE static constexpr bool IsGraph(CharType InChar) NODISCARD FORCEINLINE static constexpr bool IsGraph(CharType InChar)
{ {
if constexpr (CSameAs<CharType, char>) if constexpr (CSameAs<CharType, char>)
{ {
@ -243,7 +243,7 @@ struct TChar
} }
} }
FORCEINLINE static constexpr bool IsSpace(CharType InChar) NODISCARD FORCEINLINE static constexpr bool IsSpace(CharType InChar)
{ {
if constexpr (CSameAs<CharType, char>) if constexpr (CSameAs<CharType, char>)
{ {
@ -363,7 +363,7 @@ struct TChar
} }
} }
FORCEINLINE static constexpr bool IsBlank(CharType InChar) NODISCARD FORCEINLINE static constexpr bool IsBlank(CharType InChar)
{ {
if constexpr (CSameAs<CharType, char>) if constexpr (CSameAs<CharType, char>)
{ {
@ -404,7 +404,7 @@ struct TChar
} }
} }
FORCEINLINE static constexpr bool IsPrint(CharType InChar) NODISCARD FORCEINLINE static constexpr bool IsPrint(CharType InChar)
{ {
if constexpr (CSameAs<CharType, char>) if constexpr (CSameAs<CharType, char>)
{ {
@ -430,7 +430,7 @@ struct TChar
} }
} }
FORCEINLINE static constexpr bool IsPunct(CharType InChar) NODISCARD FORCEINLINE static constexpr bool IsPunct(CharType InChar)
{ {
if constexpr (CSameAs<CharType, char>) if constexpr (CSameAs<CharType, char>)
{ {
@ -460,7 +460,7 @@ struct TChar
} }
} }
FORCEINLINE static constexpr CharType ToLower(CharType InChar) NODISCARD FORCEINLINE static constexpr CharType ToLower(CharType InChar)
{ {
if constexpr (CSameAs<CharType, char>) if constexpr (CSameAs<CharType, char>)
{ {
@ -492,7 +492,7 @@ struct TChar
} }
} }
FORCEINLINE static constexpr CharType ToUpper(CharType InChar) NODISCARD FORCEINLINE static constexpr CharType ToUpper(CharType InChar)
{ {
if constexpr (CSameAs<CharType, char>) if constexpr (CSameAs<CharType, char>)
{ {
@ -524,7 +524,7 @@ struct TChar
} }
} }
FORCEINLINE static constexpr int ToDigit(CharType InChar) NODISCARD FORCEINLINE static constexpr int ToDigit(CharType InChar)
{ {
switch (InChar) switch (InChar)
{ {
@ -594,7 +594,7 @@ struct TChar
} }
} }
FORCEINLINE static constexpr CharType FromDigit(int InDigit) NODISCARD FORCEINLINE static constexpr CharType FromDigit(int InDigit)
{ {
if (InDigit < 0 || InDigit >= 36) return NONE; if (InDigit < 0 || InDigit >= 36) return NONE;