1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 19:58:11 +00:00

AK+LibRegex+LibWasm: Remove the non-const COWVector::operator[]

This was copying the vector behind our backs, let's remove it and make
the copying explicit by putting it behind COWVector::mutable_at().
This is a further 64% performance improvement on Wasm validation.
This commit is contained in:
Ali Mohammad Pur 2024-03-11 16:55:29 +01:00 committed by Ali Mohammad Pur
parent cced555879
commit 8003bde03d
4 changed files with 14 additions and 22 deletions

View file

@ -157,9 +157,9 @@ RegexResult Matcher<Parser>::match(Vector<RegexStringView> const& views, Optiona
for (size_t j = 0; j < c_match_preallocation_count; ++j) {
state.matches.empend();
state.capture_group_matches.empend();
state.capture_group_matches.at(j).ensure_capacity(capture_groups_count);
state.capture_group_matches.mutable_at(j).ensure_capacity(capture_groups_count);
for (size_t k = 0; k < capture_groups_count; ++k)
state.capture_group_matches.at(j).unchecked_append({});
state.capture_group_matches.mutable_at(j).unchecked_append({});
}
}
@ -169,9 +169,9 @@ RegexResult Matcher<Parser>::match(Vector<RegexStringView> const& views, Optiona
VERIFY(start_position + state.string_position - start_position <= input.view.length());
if (input.regex_options.has_flag_set(AllFlags::StringCopyMatches)) {
state.matches.at(input.match_index) = { input.view.substring_view(start_position, state.string_position - start_position).to_byte_string(), input.line, start_position, input.global_offset + start_position };
state.matches.mutable_at(input.match_index) = { input.view.substring_view(start_position, state.string_position - start_position).to_byte_string(), input.line, start_position, input.global_offset + start_position };
} else { // let the view point to the original string ...
state.matches.at(input.match_index) = { input.view.substring_view(start_position, state.string_position - start_position), input.line, start_position, input.global_offset + start_position };
state.matches.mutable_at(input.match_index) = { input.view.substring_view(start_position, state.string_position - start_position), input.line, start_position, input.global_offset + start_position };
}
};