Skip to content

Commit 970be7a

Browse files
committed
Merge pull request #80824 from MewPurPur/optimize-left-and-right
Optimize `String.left()` and `String.right()`
2 parents 5c690c3 + c9287e5 commit 970be7a

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

core/string/ustring.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -3665,7 +3665,9 @@ String String::left(int p_len) const {
36653665
return *this;
36663666
}
36673667

3668-
return substr(0, p_len);
3668+
String s;
3669+
s.copy_from_unchecked(&get_data()[0], p_len);
3670+
return s;
36693671
}
36703672

36713673
String String::right(int p_len) const {
@@ -3681,7 +3683,9 @@ String String::right(int p_len) const {
36813683
return *this;
36823684
}
36833685

3684-
return substr(length() - p_len);
3686+
String s;
3687+
s.copy_from_unchecked(&get_data()[length() - p_len], p_len);
3688+
return s;
36853689
}
36863690

36873691
char32_t String::unicode_at(int p_idx) const {

0 commit comments

Comments
 (0)