From c9287e522448c99646bad3cbd646e534782ba1d1 Mon Sep 17 00:00:00 2001 From: MewPurPur Date: Sun, 20 Aug 2023 20:01:06 +0300 Subject: [PATCH] Optimize String.left() and String.right() --- core/string/ustring.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/core/string/ustring.cpp b/core/string/ustring.cpp index 80ca51573c7..3f11459a1e2 100644 --- a/core/string/ustring.cpp +++ b/core/string/ustring.cpp @@ -3665,7 +3665,9 @@ String String::left(int p_len) const { return *this; } - return substr(0, p_len); + String s; + s.copy_from_unchecked(&get_data()[0], p_len); + return s; } String String::right(int p_len) const { @@ -3681,7 +3683,9 @@ String String::right(int p_len) const { return *this; } - return substr(length() - p_len); + String s; + s.copy_from_unchecked(&get_data()[length() - p_len], p_len); + return s; } char32_t String::unicode_at(int p_idx) const {