Skip to content

Commit

Permalink
Merge pull request #80824 from MewPurPur/optimize-left-and-right
Browse files Browse the repository at this point in the history
Optimize `String.left()` and `String.right()`
  • Loading branch information
akien-mga committed Aug 21, 2023
2 parents 5c690c3 + c9287e5 commit 970be7a
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions core/string/ustring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down

0 comments on commit 970be7a

Please sign in to comment.