Merge pull request #80824 from MewPurPur/optimize-left-and-right

Optimize `String.left()` and `String.right()`
This commit is contained in:
Rémi Verschelde 2023-08-21 08:26:15 +02:00
commit 970be7afdc
No known key found for this signature in database
GPG Key ID: C3336907360768E1
1 changed files with 6 additions and 2 deletions

View File

@ -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 {