From 04690062639c47feff664b75476543f252d16d2e Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Wed, 10 Nov 2021 12:48:07 -0500 Subject: [PATCH] LibJS: Change Intl's PatternPartition record to hold a String value It was previously holding a StringView, which was either a view into a LibUnicode-generated string or a string passed from the user. Intl.NumberFormat will need this record to hold internally-created strings, so a StringView will not suffice (the way the steps are laid out, that view will ultimately end up dangling). This shouldn't be too wasteful since the StringView it was holding was converted to a String eventually anyways. --- .../LibJS/Runtime/Intl/AbstractOperations.h | 2 +- Userland/Libraries/LibJS/Runtime/Intl/ListFormat.cpp | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Userland/Libraries/LibJS/Runtime/Intl/AbstractOperations.h b/Userland/Libraries/LibJS/Runtime/Intl/AbstractOperations.h index a2f15493ab..dbd75a3930 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/AbstractOperations.h +++ b/Userland/Libraries/LibJS/Runtime/Intl/AbstractOperations.h @@ -31,7 +31,7 @@ struct LocaleResult { struct PatternPartition { StringView type; - StringView value; + String value; }; Optional is_structurally_valid_language_tag(StringView locale); diff --git a/Userland/Libraries/LibJS/Runtime/Intl/ListFormat.cpp b/Userland/Libraries/LibJS/Runtime/Intl/ListFormat.cpp index 21fc042bc4..5ebec91ef4 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/ListFormat.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/ListFormat.cpp @@ -83,14 +83,14 @@ Vector deconstruct_pattern(StringView pattern, Placeables plac Vector result {}; // 3. For each Record { [[Type]], [[Value]] } patternPart of patternParts, do - for (auto const& pattern_part : pattern_parts) { + for (auto& pattern_part : pattern_parts) { // a. Let part be patternPart.[[Type]]. auto part = pattern_part.type; // b. If part is "literal", then if (part == "literal"sv) { // i. Append Record { [[Type]]: "literal", [[Value]]: patternPart.[[Value]] } to result. - result.append({ part, pattern_part.value }); + result.append({ part, move(pattern_part.value) }); } // c. Else, else { @@ -219,9 +219,9 @@ String format_list(ListFormat const& list_format, Vector const& list) StringBuilder result; // 3. For each Record { [[Type]], [[Value]] } part in parts, do - for (auto const& part : parts) { + for (auto& part : parts) { // a. Set result to the string-concatenation of result and part.[[Value]]. - result.append(part.value); + result.append(move(part.value)); } // 4. Return result. @@ -243,7 +243,7 @@ Array* format_list_to_parts(GlobalObject& global_object, ListFormat const& list_ size_t n = 0; // 4. For each Record { [[Type]], [[Value]] } part in parts, do - for (auto const& part : parts) { + for (auto& part : parts) { // a. Let O be OrdinaryObjectCreate(%Object.prototype%). auto* object = Object::create(global_object, global_object.object_prototype()); @@ -251,7 +251,7 @@ Array* format_list_to_parts(GlobalObject& global_object, ListFormat const& list_ MUST(object->create_data_property_or_throw(vm.names.type, js_string(vm, part.type))); // c. Perform ! CreateDataPropertyOrThrow(O, "value", part.[[Value]]). - MUST(object->create_data_property_or_throw(vm.names.value, js_string(vm, part.value))); + MUST(object->create_data_property_or_throw(vm.names.value, js_string(vm, move(part.value)))); // d. Perform ! CreateDataPropertyOrThrow(result, ! ToString(n), O). MUST(result->create_data_property_or_throw(n, object));