From 96835b856d5ad5ceaa1c46a7ef5d2f80d2b13b1b Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Mon, 1 Jun 2026 16:19:28 +0200 Subject: [PATCH] Fix StringViewAnsi substring to not allocate --- Source/Engine/Core/Types/Guid.cpp | 8 ++++---- Source/Engine/Core/Types/StringView.cpp | 8 ++++---- Source/Engine/Core/Types/StringView.h | 8 ++++---- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Source/Engine/Core/Types/Guid.cpp b/Source/Engine/Core/Types/Guid.cpp index b756969a9..6e9b31f06 100644 --- a/Source/Engine/Core/Types/Guid.cpp +++ b/Source/Engine/Core/Types/Guid.cpp @@ -101,8 +101,8 @@ FORCE_INLINE bool GuidParse(const StringViewType& text, Guid& value) // FormatType::D case 36: { - StringType b = StringType(text.Substring(9, 4)) + text.Substring(14, 4); - StringType c = StringType(text.Substring(19, 4)) + text.Substring(24, 4); + StringType b = StringType(text.Substring(9, 4)) + StringType(text.Substring(14, 4)); + StringType c = StringType(text.Substring(19, 4)) + StringType(text.Substring(24, 4)); return StringUtils::ParseHex(*text + 0, 8, &value.A) || StringUtils::ParseHex(*b, &value.B) || @@ -113,8 +113,8 @@ FORCE_INLINE bool GuidParse(const StringViewType& text, Guid& value) // FormatType::P case 38: { - StringType b = StringType(text.Substring(10, 4)) + text.Substring(15, 4); - StringType c = StringType(text.Substring(20, 4)) + text.Substring(25, 4); + StringType b = StringType(text.Substring(10, 4)) + StringType(text.Substring(15, 4)); + StringType c = StringType(text.Substring(20, 4)) + StringType(text.Substring(25, 4)); return text[0] != text[text.Length() - 1] || StringUtils::ParseHex(*text + 1, 8, &value.A) || diff --git a/Source/Engine/Core/Types/StringView.cpp b/Source/Engine/Core/Types/StringView.cpp index 168a537c1..a9b40e6a3 100644 --- a/Source/Engine/Core/Types/StringView.cpp +++ b/Source/Engine/Core/Types/StringView.cpp @@ -87,16 +87,16 @@ bool StringAnsiView::operator!=(const StringAnsi& other) const return this->Compare(StringAnsiView(other)) != 0; } -StringAnsi StringAnsiView::Substring(int32 startIndex) const +StringAnsiView StringAnsiView::Substring(int32 startIndex) const { ASSERT(startIndex >= 0 && startIndex < Length()); - return StringAnsi(Get() + startIndex, Length() - startIndex); + return StringAnsiView(Get() + startIndex, Length() - startIndex); } -StringAnsi StringAnsiView::Substring(int32 startIndex, int32 count) const +StringAnsiView StringAnsiView::Substring(int32 startIndex, int32 count) const { ASSERT(startIndex >= 0 && startIndex + count <= Length() && count >= 0); - return StringAnsi(Get() + startIndex, count); + return StringAnsiView(Get() + startIndex, count); } String StringAnsiView::ToString() const diff --git a/Source/Engine/Core/Types/StringView.h b/Source/Engine/Core/Types/StringView.h index b1025fc91..40a763bee 100644 --- a/Source/Engine/Core/Types/StringView.h +++ b/Source/Engine/Core/Types/StringView.h @@ -368,7 +368,7 @@ public: StringView Right(int32 count) const; /// - /// Retrieves substring created from characters starting from startIndex to the String end. + /// Retrieves substring created from characters starting from startIndex to the end. /// /// The index of the first character to subtract. /// The substring created from String data. @@ -550,11 +550,11 @@ public: } /// - /// Retrieves substring created from characters starting from startIndex to the String end. + /// Retrieves substring created from characters starting from startIndex to the end. /// /// The index of the first character to subtract. /// The substring created from String data. - StringAnsi Substring(int32 startIndex) const; + StringAnsiView Substring(int32 startIndex) const; /// /// Retrieves substring created from characters starting from start index. @@ -562,7 +562,7 @@ public: /// The index of the first character to subtract. /// The amount of characters to retrieve. /// The substring created from String data. - StringAnsi Substring(int32 startIndex, int32 count) const; + StringAnsiView Substring(int32 startIndex, int32 count) const; public: String ToString() const;