mirror of
https://github.com/RGBCube/serenity
synced 2025-06-01 02:28:12 +00:00
LibJS: Reduce UTF-8 to UTF-16 transcoding when only UTF-16 is wanted
When appending two strings together to form a new string, if both of the strings are already UTF-16, create the new string as UTF-16 as well. This shaves about 0.5 seconds off the following test262 test: RegExp/property-escapes/generated/General_Category_-_Decimal_Number.js
This commit is contained in:
parent
66264f7c2a
commit
b85b8ca350
2 changed files with 17 additions and 0 deletions
|
@ -1100,6 +1100,21 @@ Value add(GlobalObject& global_object, Value lhs, Value rhs)
|
|||
if (vm.exception())
|
||||
return {};
|
||||
|
||||
if (lhs_primitive.is_string() && rhs_primitive.is_string()) {
|
||||
auto const& lhs_string = lhs_primitive.as_string();
|
||||
auto const& rhs_string = rhs_primitive.as_string();
|
||||
|
||||
if (lhs_string.has_utf16_string() && rhs_string.has_utf16_string()) {
|
||||
auto const& lhs_utf16_string = lhs_string.utf16_string();
|
||||
auto const& rhs_utf16_string = rhs_string.utf16_string();
|
||||
|
||||
Vector<u16> combined;
|
||||
combined.ensure_capacity(lhs_utf16_string.length_in_code_units() + rhs_utf16_string.length_in_code_units());
|
||||
combined.extend(lhs_utf16_string.string());
|
||||
combined.extend(rhs_utf16_string.string());
|
||||
return js_string(vm.heap(), Utf16String(move(combined)));
|
||||
}
|
||||
}
|
||||
if (lhs_primitive.is_string() || rhs_primitive.is_string()) {
|
||||
auto lhs_string = lhs_primitive.to_string(global_object);
|
||||
if (vm.exception())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue