From c5b5c779ff9e10ce8b2538843c0f921b0f197907 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Thu, 19 Aug 2021 06:48:32 -0400 Subject: [PATCH] LibRegex+LibJS: Change capture group names from a String to a FlyString The parser now stores this as a FlyString everywhere, so consumers can also use it as a FlyString. --- Userland/Libraries/LibJS/Runtime/RegExpPrototype.cpp | 6 +++--- Userland/Libraries/LibRegex/RegexMatch.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Userland/Libraries/LibJS/Runtime/RegExpPrototype.cpp b/Userland/Libraries/LibJS/Runtime/RegExpPrototype.cpp index 1b5edc8a314..7a185f1446a 100644 --- a/Userland/Libraries/LibJS/Runtime/RegExpPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/RegExpPrototype.cpp @@ -141,7 +141,7 @@ static Value get_match_indices_array(GlobalObject& global_object, Utf16View cons } // 1.1.4.1.5 MakeIndicesArray ( S , indices, groupNames, hasGroups ), https://tc39.es/proposal-regexp-match-indices/#sec-makeindicesarray -static Value make_indices_array(GlobalObject& global_object, Utf16View const& string, Vector> const& indices, HashMap const& group_names, bool has_groups) +static Value make_indices_array(GlobalObject& global_object, Utf16View const& string, Vector> const& indices, HashMap const& group_names, bool has_groups) { // Note: This implementation differs from the spec, but has the same behavior. // @@ -268,7 +268,7 @@ static Value regexp_builtin_exec(GlobalObject& global_object, RegExpObject& rege return {}; Vector> indices { Match::create(match) }; - HashMap group_names; + HashMap group_names; bool has_groups = result.n_named_capture_groups != 0; Object* groups_object = has_groups ? Object::create(global_object, nullptr) : nullptr; @@ -285,7 +285,7 @@ static Value regexp_builtin_exec(GlobalObject& global_object, RegExpObject& rege array->create_data_property_or_throw(i + 1, capture_value); if (capture.capture_group_name.has_value()) { - auto group_name = capture.capture_group_name->to_string(); + auto group_name = capture.capture_group_name.release_value(); groups_object->create_data_property_or_throw(group_name, js_string(vm, capture.view.u16_view())); group_names.set(move(group_name), Match::create(capture)); } diff --git a/Userland/Libraries/LibRegex/RegexMatch.h b/Userland/Libraries/LibRegex/RegexMatch.h index f11eb860b1d..71cf3f1f1e6 100644 --- a/Userland/Libraries/LibRegex/RegexMatch.h +++ b/Userland/Libraries/LibRegex/RegexMatch.h @@ -487,7 +487,7 @@ public: } RegexStringView view { nullptr }; - Optional capture_group_name {}; + Optional capture_group_name {}; size_t line { 0 }; size_t column { 0 }; size_t global_offset { 0 };