LibWeb: Avoid LayoutState hash lookups in more parts of float layout

This commit is contained in:
Andreas Kling 2024-01-23 21:10:17 +01:00
parent 11d2e6101f
commit 4e6de47f93
Notes: sideshowbarker 2024-07-17 02:05:41 +09:00
3 changed files with 11 additions and 6 deletions

View file

@ -1134,7 +1134,7 @@ void BlockFormattingContext::layout_list_item_marker(ListItemBox const& list_ite
}
auto offset_y = max(CSSPixels(0), (marker.computed_values().line_height() - marker_state.content_height()) / 2);
auto space_and_containing_margin = intrusion_by_floats_into_box(list_item_box, offset_y);
auto space_and_containing_margin = intrusion_by_floats_into_box(list_item_state, offset_y);
marker_state.set_content_offset({ space_and_containing_margin.left - final_marker_width, offset_y });
if (marker_state.content_height() > list_item_state.content_height())
@ -1183,9 +1183,13 @@ BlockFormattingContext::SpaceUsedAndContainingMarginForFloats BlockFormattingCon
}
FormattingContext::SpaceUsedByFloats BlockFormattingContext::intrusion_by_floats_into_box(Box const& box, CSSPixels y_in_box) const
{
return intrusion_by_floats_into_box(m_state.get(box), y_in_box);
}
FormattingContext::SpaceUsedByFloats BlockFormattingContext::intrusion_by_floats_into_box(LayoutState::UsedValues const& box_used_values, CSSPixels y_in_box) const
{
// NOTE: Floats are relative to the BFC root box, not necessarily the containing block of this IFC.
auto& box_used_values = m_state.get(box);
auto box_in_root_rect = content_box_rect_in_ancestor_coordinate_space(box_used_values, root());
CSSPixels y_in_root = box_in_root_rect.y() + y_in_box;
auto space_and_containing_margin = space_used_and_containing_margin_for_floats(y_in_root);

View file

@ -42,7 +42,8 @@ public:
void add_absolutely_positioned_box(Box const& box) { m_absolutely_positioned_boxes.append(box); }
SpaceUsedAndContainingMarginForFloats space_used_and_containing_margin_for_floats(CSSPixels y) const;
SpaceUsedByFloats intrusion_by_floats_into_box(Box const&, CSSPixels y_in_box) const;
[[nodiscard]] SpaceUsedByFloats intrusion_by_floats_into_box(Box const&, CSSPixels y_in_box) const;
[[nodiscard]] SpaceUsedByFloats intrusion_by_floats_into_box(LayoutState::UsedValues const&, CSSPixels y_in_box) const;
virtual CSSPixels greatest_child_width(Box const&) const override;

View file

@ -55,7 +55,7 @@ CSSPixels InlineFormattingContext::leftmost_x_offset_at(CSSPixels y) const
AvailableSize InlineFormattingContext::available_space_for_line(CSSPixels y) const
{
auto intrusions = parent().intrusion_by_floats_into_box(containing_block(), y);
auto intrusions = parent().intrusion_by_floats_into_box(m_containing_block_state, y);
if (m_available_space->width.is_definite()) {
return AvailableSize::make_definite(m_available_space->width.to_px_or_zero() - (intrusions.left + intrusions.right));
} else {
@ -379,8 +379,8 @@ bool InlineFormattingContext::any_floats_intrude_at_y(CSSPixels y) const
bool InlineFormattingContext::can_fit_new_line_at_y(CSSPixels y) const
{
auto top_intrusions = parent().intrusion_by_floats_into_box(containing_block(), y);
auto bottom_intrusions = parent().intrusion_by_floats_into_box(containing_block(), y + containing_block().computed_values().line_height() - 1);
auto top_intrusions = parent().intrusion_by_floats_into_box(m_containing_block_state, y);
auto bottom_intrusions = parent().intrusion_by_floats_into_box(m_containing_block_state, y + containing_block().computed_values().line_height() - 1);
auto left_edge = [](auto& space) -> CSSPixels {
return space.left;