From 716bf5cb7aa1188efab65e8db9188dcb2bc6c644 Mon Sep 17 00:00:00 2001 From: Tim Ledbetter Date: Fri, 28 Jun 2024 21:16:29 +0100 Subject: [PATCH] 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. (cherry picked from commit e76ad9492e0992f9a6d821240bea2b62f27a03c8) --- Userland/Libraries/LibWeb/DOM/Document.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Userland/Libraries/LibWeb/DOM/Document.cpp b/Userland/Libraries/LibWeb/DOM/Document.cpp index 247bc39d182dff..878fbd6c66489b 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.cpp +++ b/Userland/Libraries/LibWeb/DOM/Document.cpp @@ -5219,10 +5219,8 @@ Vector> 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) @@ -5230,9 +5228,8 @@ Vector> 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())