From 00838c2e35774fcf09c61e3a4ebbeb08f2d231d9 Mon Sep 17 00:00:00 2001 From: Redstone1024 <2824517378@qq.com> Date: Sat, 21 Sep 2024 15:54:01 +0800 Subject: [PATCH] perf(string): add NODISCARD tag to some functions --- .../Source/Public/String/CString.h | 28 +++++----- Redcraft.Utility/Source/Public/String/Char.h | 52 +++++++++---------- 2 files changed, 40 insertions(+), 40 deletions(-) diff --git a/Redcraft.Utility/Source/Public/String/CString.h b/Redcraft.Utility/Source/Public/String/CString.h index 149364d..1ac9d9a 100644 --- a/Redcraft.Utility/Source/Public/String/CString.h +++ b/Redcraft.Utility/Source/Public/String/CString.h @@ -97,7 +97,7 @@ struct TCString } /** @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."); @@ -126,7 +126,7 @@ struct TCString } /** 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."); @@ -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. */ template 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."); @@ -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. */ template 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."); @@ -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. */ - 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."); @@ -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. */ - 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."); @@ -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. */ - 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."); @@ -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. */ - 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."); @@ -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. */ - 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."); @@ -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. */ - 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."); @@ -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. */ - 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."); @@ -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. */ - 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."); @@ -365,7 +365,7 @@ struct TCString } /** 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."); @@ -421,7 +421,7 @@ struct TCString } /** 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."); diff --git a/Redcraft.Utility/Source/Public/String/Char.h b/Redcraft.Utility/Source/Public/String/Char.h index 63a5bdc..83a1bbf 100644 --- a/Redcraft.Utility/Source/Public/String/Char.h +++ b/Redcraft.Utility/Source/Public/String/Char.h @@ -22,36 +22,36 @@ struct TLiteral; template <> struct TLiteral { - 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; } + 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 <> struct TLiteral { - 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; } + 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 <> struct TLiteral { - 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; } + 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 <> struct TLiteral { - 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; } + 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 <> struct TLiteral { - 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; } + 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 @@ -67,7 +67,7 @@ struct TChar 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) { @@ -83,7 +83,7 @@ struct TChar } } - FORCEINLINE static constexpr bool IsAlpha(CharType InChar) + NODISCARD FORCEINLINE static constexpr bool IsAlpha(CharType InChar) { if constexpr (CSameAs) { @@ -111,7 +111,7 @@ struct TChar } } - FORCEINLINE static constexpr bool IsLower(CharType InChar) + NODISCARD FORCEINLINE static constexpr bool IsLower(CharType InChar) { if constexpr (CSameAs) { @@ -137,7 +137,7 @@ struct TChar } } - FORCEINLINE static constexpr bool IsUpper(CharType InChar) + NODISCARD FORCEINLINE static constexpr bool IsUpper(CharType InChar) { if constexpr (CSameAs) { @@ -163,13 +163,13 @@ struct TChar } } - FORCEINLINE static constexpr bool IsDigit(CharType InChar) + NODISCARD FORCEINLINE static constexpr bool IsDigit(CharType InChar) { /* ..; */ 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].")); @@ -180,7 +180,7 @@ struct TChar (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) { @@ -217,7 +217,7 @@ struct TChar } } - FORCEINLINE static constexpr bool IsGraph(CharType InChar) + NODISCARD FORCEINLINE static constexpr bool IsGraph(CharType InChar) { if constexpr (CSameAs) { @@ -243,7 +243,7 @@ struct TChar } } - FORCEINLINE static constexpr bool IsSpace(CharType InChar) + NODISCARD FORCEINLINE static constexpr bool IsSpace(CharType InChar) { if constexpr (CSameAs) { @@ -363,7 +363,7 @@ struct TChar } } - FORCEINLINE static constexpr bool IsBlank(CharType InChar) + NODISCARD FORCEINLINE static constexpr bool IsBlank(CharType InChar) { if constexpr (CSameAs) { @@ -404,7 +404,7 @@ struct TChar } } - FORCEINLINE static constexpr bool IsPrint(CharType InChar) + NODISCARD FORCEINLINE static constexpr bool IsPrint(CharType InChar) { if constexpr (CSameAs) { @@ -430,7 +430,7 @@ struct TChar } } - FORCEINLINE static constexpr bool IsPunct(CharType InChar) + NODISCARD FORCEINLINE static constexpr bool IsPunct(CharType InChar) { if constexpr (CSameAs) { @@ -460,7 +460,7 @@ struct TChar } } - FORCEINLINE static constexpr CharType ToLower(CharType InChar) + NODISCARD FORCEINLINE static constexpr CharType ToLower(CharType InChar) { if constexpr (CSameAs) { @@ -492,7 +492,7 @@ struct TChar } } - FORCEINLINE static constexpr CharType ToUpper(CharType InChar) + NODISCARD FORCEINLINE static constexpr CharType ToUpper(CharType InChar) { if constexpr (CSameAs) { @@ -524,7 +524,7 @@ struct TChar } } - FORCEINLINE static constexpr int ToDigit(CharType InChar) + NODISCARD FORCEINLINE static constexpr int ToDigit(CharType 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;