mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 04:07:44 +00:00
LibJS: Reduce copying of string data in String.prototype
The primary themes here are invoking js_string() with existing instances of Utf16String when possible, and not creating entire UTF-8 copies when not needed.
This commit is contained in:
parent
daf559c717
commit
6c45620709
2 changed files with 75 additions and 120 deletions
|
@ -595,17 +595,17 @@ String get_substitution(GlobalObject& global_object, Utf16View const& matched, U
|
|||
result.append('$');
|
||||
++i;
|
||||
} else if (next == '&') {
|
||||
result.append(matched.to_utf8(Utf16View::AllowInvalidCodeUnits::Yes));
|
||||
result.append(matched);
|
||||
++i;
|
||||
} else if (next == '`') {
|
||||
auto substring = str.substring_view(0, position);
|
||||
result.append(substring.to_utf8(Utf16View::AllowInvalidCodeUnits::Yes));
|
||||
result.append(substring);
|
||||
++i;
|
||||
} else if (next == '\'') {
|
||||
auto tail_pos = position + matched.length_in_code_units();
|
||||
if (tail_pos < str.length_in_code_units()) {
|
||||
auto substring = str.substring_view(tail_pos);
|
||||
result.append(substring.to_utf8(Utf16View::AllowInvalidCodeUnits::Yes));
|
||||
result.append(substring);
|
||||
}
|
||||
++i;
|
||||
} else if (is_ascii_digit(next)) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue