Skip to content

Commit

Permalink
LibRegex+LibJS: Change capture group names from a String to a FlyString
Browse files Browse the repository at this point in the history
The parser now stores this as a FlyString everywhere, so consumers can
also use it as a FlyString.
  • Loading branch information
trflynn89 authored and awesomekling committed Aug 19, 2021
1 parent 4f2cbe1 commit c5b5c77
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions Userland/Libraries/LibJS/Runtime/RegExpPrototype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Optional<Match>> const& indices, HashMap<String, Match> const& group_names, bool has_groups)
static Value make_indices_array(GlobalObject& global_object, Utf16View const& string, Vector<Optional<Match>> const& indices, HashMap<FlyString, Match> const& group_names, bool has_groups)
{
// Note: This implementation differs from the spec, but has the same behavior.
//
Expand Down Expand Up @@ -268,7 +268,7 @@ static Value regexp_builtin_exec(GlobalObject& global_object, RegExpObject& rege
return {};

Vector<Optional<Match>> indices { Match::create(match) };
HashMap<String, Match> group_names;
HashMap<FlyString, Match> group_names;

bool has_groups = result.n_named_capture_groups != 0;
Object* groups_object = has_groups ? Object::create(global_object, nullptr) : nullptr;
Expand All @@ -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));
}
Expand Down
2 changes: 1 addition & 1 deletion Userland/Libraries/LibRegex/RegexMatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ class Match final {
}

RegexStringView view { nullptr };
Optional<StringView> capture_group_name {};
Optional<FlyString> capture_group_name {};
size_t line { 0 };
size_t column { 0 };
size_t global_offset { 0 };
Expand Down

0 comments on commit c5b5c77

Please sign in to comment.