LibWeb: Elide boundary checks when constructing find in page ranges
Previously, unnecessary boundary checks were being done when constructing the range objects used to represent find in page matches. These checks are no longer performed leading to a significant speedup when performing find in page queries on pages containing a lot of text.
This commit is contained in:
parent
156c1083e9
commit
e76ad9492e
Notes:
sideshowbarker
2024-07-17 04:09:56 +09:00
Author: https://github.com/tcl3 Commit: https://github.com/LadybirdBrowser/ladybird/commit/e76ad9492e Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/311 Reviewed-by: https://github.com/kalenikaliaksandr
1 changed files with 1 additions and 4 deletions
|
@ -5137,10 +5137,8 @@ Vector<JS::Handle<DOM::Range>> Document::find_matching_text(String const& query,
|
|||
for (; i < text_block.positions.size() - 1 && match_index.value() > text_block.positions[i + 1].start_offset; ++i)
|
||||
match_start_position = &text_block.positions[i + 1];
|
||||
|
||||
auto range = create_range();
|
||||
auto start_position = match_index.value() - match_start_position->start_offset;
|
||||
auto& start_dom_node = match_start_position->dom_node;
|
||||
(void)range->set_start(start_dom_node, start_position);
|
||||
|
||||
auto* match_end_position = match_start_position;
|
||||
for (; i < text_block.positions.size() - 1 && (match_index.value() + query.bytes_as_string_view().length() > text_block.positions[i + 1].start_offset); ++i)
|
||||
|
@ -5148,9 +5146,8 @@ Vector<JS::Handle<DOM::Range>> Document::find_matching_text(String const& query,
|
|||
|
||||
auto& end_dom_node = match_end_position->dom_node;
|
||||
auto end_position = match_index.value() + query.bytes_as_string_view().length() - match_end_position->start_offset;
|
||||
(void)range->set_end(end_dom_node, end_position);
|
||||
|
||||
matches.append(range);
|
||||
matches.append(Range::create(start_dom_node, start_position, end_dom_node, end_position));
|
||||
match_start_position = match_end_position;
|
||||
offset = match_index.value() + query.bytes_as_string_view().length() + 1;
|
||||
if (offset >= text.bytes_as_string_view().length())
|
||||
|
|
Loading…
Add table
Reference in a new issue