layout: get rid of some collect() calls (#42327)

Profiling a speedometer run showed significant time spent in some layout
function in vector allocations. The main change is to switch the result
of `query_box_areas()` from a Vec<T> to and iterator.

Testing: refactoring with no expected test changes

Signed-off-by: webbeef <me@webbeef.org>
This commit is contained in:
webbeef
2026-02-06 01:38:49 -08:00
committed by GitHub
parent 10209cc183
commit 86403fa4e5
7 changed files with 37 additions and 54 deletions

View File

@@ -56,11 +56,11 @@ use js::rust::{
MutableHandleValue,
};
use layout_api::{
BoxAreaType, ElementsFromPointFlags, ElementsFromPointResult, FragmentType, Layout,
LayoutImageDestination, PendingImage, PendingImageState, PendingRasterizationImage,
PhysicalSides, QueryMsg, ReflowGoal, ReflowPhasesRun, ReflowRequest, ReflowRequestRestyle,
RestyleReason, ScrollContainerQueryFlags, ScrollContainerResponse, TrustedNodeAddress,
combine_id_with_fragment_type,
BoxAreaType, CSSPixelRectIterator, ElementsFromPointFlags, ElementsFromPointResult,
FragmentType, Layout, LayoutImageDestination, PendingImage, PendingImageState,
PendingRasterizationImage, PhysicalSides, QueryMsg, ReflowGoal, ReflowPhasesRun, ReflowRequest,
ReflowRequestRestyle, RestyleReason, ScrollContainerQueryFlags, ScrollContainerResponse,
TrustedNodeAddress, combine_id_with_fragment_type,
};
use malloc_size_of::MallocSizeOf;
use media::WindowGLContext;
@@ -2851,11 +2851,7 @@ impl Window {
self.box_area_query_without_reflow(node, area, exclude_transform_and_inline)
}
pub(crate) fn box_areas_query(
&self,
node: &Node,
area: BoxAreaType,
) -> Vec<Rect<Au, CSSPixel>> {
pub(crate) fn box_areas_query(&self, node: &Node, area: BoxAreaType) -> CSSPixelRectIterator {
self.layout_reflow(QueryMsg::BoxAreas);
self.layout
.borrow()