mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 02:17:34 +00:00
LibWeb: Avoid more UsedValues hash lookups in BFC and IFC
This commit is contained in:
parent
7a34f1a4e2
commit
954c4496b1
2 changed files with 23 additions and 29 deletions
|
@ -837,7 +837,7 @@ BlockFormattingContext::DidIntroduceClearance BlockFormattingContext::clear_floa
|
||||||
// First, find the lowest margin box edge on this float side and calculate the Y offset just below it.
|
// First, find the lowest margin box edge on this float side and calculate the Y offset just below it.
|
||||||
CSSPixels clearance_y_in_root = 0;
|
CSSPixels clearance_y_in_root = 0;
|
||||||
for (auto const& floating_box : float_side.current_boxes) {
|
for (auto const& floating_box : float_side.current_boxes) {
|
||||||
auto floating_box_rect_in_root = margin_box_rect_in_ancestor_coordinate_space(floating_box.box, root());
|
auto floating_box_rect_in_root = margin_box_rect_in_ancestor_coordinate_space(floating_box.used_values, root());
|
||||||
clearance_y_in_root = max(clearance_y_in_root, floating_box_rect_in_root.bottom());
|
clearance_y_in_root = max(clearance_y_in_root, floating_box_rect_in_root.bottom());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -897,7 +897,7 @@ void BlockFormattingContext::place_block_level_element_in_normal_flow_horizontal
|
||||||
|
|
||||||
if ((!m_left_floats.current_boxes.is_empty() || !m_right_floats.current_boxes.is_empty())
|
if ((!m_left_floats.current_boxes.is_empty() || !m_right_floats.current_boxes.is_empty())
|
||||||
&& creates_block_formatting_context(child_box)) {
|
&& creates_block_formatting_context(child_box)) {
|
||||||
auto box_in_root_rect = content_box_rect_in_ancestor_coordinate_space(child_box, root());
|
auto box_in_root_rect = content_box_rect_in_ancestor_coordinate_space(box_state, root());
|
||||||
auto space_and_containing_margin = space_used_and_containing_margin_for_floats(box_in_root_rect.y());
|
auto space_and_containing_margin = space_used_and_containing_margin_for_floats(box_in_root_rect.y());
|
||||||
available_width_within_containing_block -= space_and_containing_margin.left_used_space + space_and_containing_margin.right_used_space;
|
available_width_within_containing_block -= space_and_containing_margin.left_used_space + space_and_containing_margin.right_used_space;
|
||||||
auto const& containing_box_state = m_state.get(*child_box.containing_block());
|
auto const& containing_box_state = m_state.get(*child_box.containing_block());
|
||||||
|
@ -972,7 +972,7 @@ void BlockFormattingContext::layout_floating_box(Box const& box, BlockContainer
|
||||||
offset_from_edge = box_state.content_width() + box_state.margin_box_right();
|
offset_from_edge = box_state.content_width() + box_state.margin_box_right();
|
||||||
};
|
};
|
||||||
|
|
||||||
auto box_in_root_rect = content_box_rect_in_ancestor_coordinate_space(box, root());
|
auto box_in_root_rect = content_box_rect_in_ancestor_coordinate_space(box_state, root());
|
||||||
CSSPixels y_in_root = box_in_root_rect.y();
|
CSSPixels y_in_root = box_in_root_rect.y();
|
||||||
CSSPixels y = box_state.offset.y();
|
CSSPixels y = box_state.offset.y();
|
||||||
|
|
||||||
|
@ -993,8 +993,7 @@ void BlockFormattingContext::layout_floating_box(Box const& box, BlockContainer
|
||||||
// Walk all currently tracked floats on the side we're floating towards.
|
// Walk all currently tracked floats on the side we're floating towards.
|
||||||
// We're looking for the innermost preceding float that intersects vertically with `box`.
|
// We're looking for the innermost preceding float that intersects vertically with `box`.
|
||||||
for (auto& preceding_float : side_data.current_boxes.in_reverse()) {
|
for (auto& preceding_float : side_data.current_boxes.in_reverse()) {
|
||||||
auto const& preceding_float_state = m_state.get(preceding_float.box);
|
auto const preceding_float_rect = margin_box_rect_in_ancestor_coordinate_space(preceding_float.used_values, root());
|
||||||
auto const preceding_float_rect = margin_box_rect_in_ancestor_coordinate_space(preceding_float_state, root());
|
|
||||||
if (!preceding_float_rect.contains_vertically(y_in_root))
|
if (!preceding_float_rect.contains_vertically(y_in_root))
|
||||||
continue;
|
continue;
|
||||||
// We found a preceding float that intersects vertically with the current float.
|
// We found a preceding float that intersects vertically with the current float.
|
||||||
|
@ -1002,14 +1001,14 @@ void BlockFormattingContext::layout_floating_box(Box const& box, BlockContainer
|
||||||
CSSPixels tentative_offset_from_edge = 0;
|
CSSPixels tentative_offset_from_edge = 0;
|
||||||
bool fits_next_to_preceding_float = false;
|
bool fits_next_to_preceding_float = false;
|
||||||
if (side == FloatSide::Left) {
|
if (side == FloatSide::Left) {
|
||||||
tentative_offset_from_edge = max(preceding_float.offset_from_edge + preceding_float_state.content_width() + preceding_float_state.margin_box_right(), 0) + box_state.margin_box_left();
|
tentative_offset_from_edge = max(preceding_float.offset_from_edge + preceding_float.used_values.content_width() + preceding_float.used_values.margin_box_right(), 0) + box_state.margin_box_left();
|
||||||
if (available_space.width.is_definite()) {
|
if (available_space.width.is_definite()) {
|
||||||
fits_next_to_preceding_float = (tentative_offset_from_edge + box_state.content_width() + box_state.margin_box_right()) <= available_space.width.to_px_or_zero();
|
fits_next_to_preceding_float = (tentative_offset_from_edge + box_state.content_width() + box_state.margin_box_right()) <= available_space.width.to_px_or_zero();
|
||||||
} else if (available_space.width.is_max_content() || available_space.width.is_indefinite()) {
|
} else if (available_space.width.is_max_content() || available_space.width.is_indefinite()) {
|
||||||
fits_next_to_preceding_float = true;
|
fits_next_to_preceding_float = true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
tentative_offset_from_edge = preceding_float.offset_from_edge + preceding_float_state.margin_box_left() + box_state.margin_box_right() + box_state.content_width();
|
tentative_offset_from_edge = preceding_float.offset_from_edge + preceding_float.used_values.margin_box_left() + box_state.margin_box_right() + box_state.content_width();
|
||||||
fits_next_to_preceding_float = tentative_offset_from_edge >= 0;
|
fits_next_to_preceding_float = tentative_offset_from_edge >= 0;
|
||||||
}
|
}
|
||||||
did_touch_preceding_float = true;
|
did_touch_preceding_float = true;
|
||||||
|
@ -1035,9 +1034,8 @@ void BlockFormattingContext::layout_floating_box(Box const& box, BlockContainer
|
||||||
// Either way, we float this box all the way to the edge.
|
// Either way, we float this box all the way to the edge.
|
||||||
float_to_edge();
|
float_to_edge();
|
||||||
CSSPixels lowest_margin_edge = 0;
|
CSSPixels lowest_margin_edge = 0;
|
||||||
for (auto const& box : side_data.current_boxes) {
|
for (auto const& current : side_data.current_boxes) {
|
||||||
auto const& box_state = m_state.get(box.box);
|
lowest_margin_edge = max(lowest_margin_edge, current.used_values.margin_box_height());
|
||||||
lowest_margin_edge = max(lowest_margin_edge, box_state.margin_box_height());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
side_data.y_offset += lowest_margin_edge;
|
side_data.y_offset += lowest_margin_edge;
|
||||||
|
@ -1149,17 +1147,16 @@ BlockFormattingContext::SpaceUsedAndContainingMarginForFloats BlockFormattingCon
|
||||||
|
|
||||||
for (auto const& floating_box_ptr : m_left_floats.all_boxes.in_reverse()) {
|
for (auto const& floating_box_ptr : m_left_floats.all_boxes.in_reverse()) {
|
||||||
auto const& floating_box = *floating_box_ptr;
|
auto const& floating_box = *floating_box_ptr;
|
||||||
auto const& floating_box_state = m_state.get(floating_box.box);
|
|
||||||
// NOTE: The floating box is *not* in the final horizontal position yet, but the size and vertical position is valid.
|
// NOTE: The floating box is *not* in the final horizontal position yet, but the size and vertical position is valid.
|
||||||
auto rect = margin_box_rect_in_ancestor_coordinate_space(floating_box_state, root());
|
auto rect = margin_box_rect_in_ancestor_coordinate_space(floating_box.used_values, root());
|
||||||
if (rect.contains_vertically(y)) {
|
if (rect.contains_vertically(y)) {
|
||||||
CSSPixels offset_from_containing_block_chain_margins_between_here_and_root = 0;
|
CSSPixels offset_from_containing_block_chain_margins_between_here_and_root = 0;
|
||||||
for (auto const* containing_block = floating_box_state.containing_block_used_values(); containing_block && &containing_block->node() != &root(); containing_block = containing_block->containing_block_used_values()) {
|
for (auto const* containing_block = floating_box.used_values.containing_block_used_values(); containing_block && &containing_block->node() != &root(); containing_block = containing_block->containing_block_used_values()) {
|
||||||
offset_from_containing_block_chain_margins_between_here_and_root += containing_block->margin_box_left();
|
offset_from_containing_block_chain_margins_between_here_and_root += containing_block->margin_box_left();
|
||||||
}
|
}
|
||||||
space_and_containing_margin.left_used_space = floating_box.offset_from_edge
|
space_and_containing_margin.left_used_space = floating_box.offset_from_edge
|
||||||
+ floating_box_state.content_width()
|
+ floating_box.used_values.content_width()
|
||||||
+ floating_box_state.margin_box_right();
|
+ floating_box.used_values.margin_box_right();
|
||||||
space_and_containing_margin.left_total_containing_margin = offset_from_containing_block_chain_margins_between_here_and_root;
|
space_and_containing_margin.left_total_containing_margin = offset_from_containing_block_chain_margins_between_here_and_root;
|
||||||
space_and_containing_margin.matching_left_float_box = floating_box.box.ptr();
|
space_and_containing_margin.matching_left_float_box = floating_box.box.ptr();
|
||||||
break;
|
break;
|
||||||
|
@ -1168,16 +1165,15 @@ BlockFormattingContext::SpaceUsedAndContainingMarginForFloats BlockFormattingCon
|
||||||
|
|
||||||
for (auto const& floating_box_ptr : m_right_floats.all_boxes.in_reverse()) {
|
for (auto const& floating_box_ptr : m_right_floats.all_boxes.in_reverse()) {
|
||||||
auto const& floating_box = *floating_box_ptr;
|
auto const& floating_box = *floating_box_ptr;
|
||||||
auto const& floating_box_state = m_state.get(floating_box.box);
|
|
||||||
// NOTE: The floating box is *not* in the final horizontal position yet, but the size and vertical position is valid.
|
// NOTE: The floating box is *not* in the final horizontal position yet, but the size and vertical position is valid.
|
||||||
auto rect = margin_box_rect_in_ancestor_coordinate_space(floating_box_state, root());
|
auto rect = margin_box_rect_in_ancestor_coordinate_space(floating_box.used_values, root());
|
||||||
if (rect.contains_vertically(y)) {
|
if (rect.contains_vertically(y)) {
|
||||||
CSSPixels offset_from_containing_block_chain_margins_between_here_and_root = 0;
|
CSSPixels offset_from_containing_block_chain_margins_between_here_and_root = 0;
|
||||||
for (auto const* containing_block = floating_box_state.containing_block_used_values(); containing_block && &containing_block->node() != &root(); containing_block = containing_block->containing_block_used_values()) {
|
for (auto const* containing_block = floating_box.used_values.containing_block_used_values(); containing_block && &containing_block->node() != &root(); containing_block = containing_block->containing_block_used_values()) {
|
||||||
offset_from_containing_block_chain_margins_between_here_and_root += containing_block->margin_box_right();
|
offset_from_containing_block_chain_margins_between_here_and_root += containing_block->margin_box_right();
|
||||||
}
|
}
|
||||||
space_and_containing_margin.right_used_space = floating_box.offset_from_edge
|
space_and_containing_margin.right_used_space = floating_box.offset_from_edge
|
||||||
+ floating_box_state.margin_box_left();
|
+ floating_box.used_values.margin_box_left();
|
||||||
space_and_containing_margin.right_total_containing_margin = offset_from_containing_block_chain_margins_between_here_and_root;
|
space_and_containing_margin.right_total_containing_margin = offset_from_containing_block_chain_margins_between_here_and_root;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1189,7 +1185,8 @@ BlockFormattingContext::SpaceUsedAndContainingMarginForFloats BlockFormattingCon
|
||||||
FormattingContext::SpaceUsedByFloats BlockFormattingContext::intrusion_by_floats_into_box(Box const& box, CSSPixels y_in_box) const
|
FormattingContext::SpaceUsedByFloats BlockFormattingContext::intrusion_by_floats_into_box(Box const& box, CSSPixels y_in_box) const
|
||||||
{
|
{
|
||||||
// NOTE: Floats are relative to the BFC root box, not necessarily the containing block of this IFC.
|
// NOTE: Floats are relative to the BFC root box, not necessarily the containing block of this IFC.
|
||||||
auto box_in_root_rect = content_box_rect_in_ancestor_coordinate_space(box, root());
|
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;
|
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);
|
auto space_and_containing_margin = space_used_and_containing_margin_for_floats(y_in_root);
|
||||||
auto left_side_floats_limit_to_right = space_and_containing_margin.left_total_containing_margin + space_and_containing_margin.left_used_space;
|
auto left_side_floats_limit_to_right = space_and_containing_margin.left_total_containing_margin + space_and_containing_margin.left_used_space;
|
||||||
|
@ -1198,9 +1195,8 @@ FormattingContext::SpaceUsedByFloats BlockFormattingContext::intrusion_by_floats
|
||||||
auto left_intrusion = max(CSSPixels(0), left_side_floats_limit_to_right - max(CSSPixels(0), box_in_root_rect.x()));
|
auto left_intrusion = max(CSSPixels(0), left_side_floats_limit_to_right - max(CSSPixels(0), box_in_root_rect.x()));
|
||||||
|
|
||||||
CSSPixels offset_from_containing_block_chain_margins_between_here_and_root = 0;
|
CSSPixels offset_from_containing_block_chain_margins_between_here_and_root = 0;
|
||||||
for (auto const* containing_block = static_cast<Box const*>(&box); containing_block && containing_block != &root(); containing_block = containing_block->containing_block()) {
|
for (auto const* containing_block = &box_used_values; containing_block && &containing_block->node() != &root(); containing_block = containing_block->containing_block_used_values()) {
|
||||||
auto const& containing_block_state = m_state.get(*containing_block);
|
offset_from_containing_block_chain_margins_between_here_and_root = max(offset_from_containing_block_chain_margins_between_here_and_root, containing_block->margin_box_right());
|
||||||
offset_from_containing_block_chain_margins_between_here_and_root = max(offset_from_containing_block_chain_margins_between_here_and_root, containing_block_state.margin_box_right());
|
|
||||||
}
|
}
|
||||||
auto right_intrusion = max(CSSPixels(0), right_side_floats_limit_to_right - offset_from_containing_block_chain_margins_between_here_and_root);
|
auto right_intrusion = max(CSSPixels(0), right_side_floats_limit_to_right - offset_from_containing_block_chain_margins_between_here_and_root);
|
||||||
|
|
||||||
|
@ -1221,8 +1217,7 @@ CSSPixels BlockFormattingContext::greatest_child_width(Box const& box) const
|
||||||
if (left_float->box->containing_block() != &box)
|
if (left_float->box->containing_block() != &box)
|
||||||
continue;
|
continue;
|
||||||
if (line_box.baseline() >= left_float->top_margin_edge || line_box.baseline() <= left_float->bottom_margin_edge) {
|
if (line_box.baseline() >= left_float->top_margin_edge || line_box.baseline() <= left_float->bottom_margin_edge) {
|
||||||
auto const& left_float_state = m_state.get(left_float->box);
|
extra_width_from_left_floats = max(extra_width_from_left_floats, left_float->offset_from_edge + left_float->used_values.content_width() + left_float->used_values.margin_box_right());
|
||||||
extra_width_from_left_floats = max(extra_width_from_left_floats, left_float->offset_from_edge + left_float_state.content_width() + left_float_state.margin_box_right());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
CSSPixels extra_width_from_right_floats = 0;
|
CSSPixels extra_width_from_right_floats = 0;
|
||||||
|
@ -1231,8 +1226,7 @@ CSSPixels BlockFormattingContext::greatest_child_width(Box const& box) const
|
||||||
if (right_float->box->containing_block() != &box)
|
if (right_float->box->containing_block() != &box)
|
||||||
continue;
|
continue;
|
||||||
if (line_box.baseline() >= right_float->top_margin_edge || line_box.baseline() <= right_float->bottom_margin_edge) {
|
if (line_box.baseline() >= right_float->top_margin_edge || line_box.baseline() <= right_float->bottom_margin_edge) {
|
||||||
auto const& right_float_state = m_state.get(right_float->box);
|
extra_width_from_right_floats = max(extra_width_from_right_floats, right_float->offset_from_edge + right_float->used_values.margin_box_left());
|
||||||
extra_width_from_right_floats = max(extra_width_from_right_floats, right_float->offset_from_edge + right_float_state.margin_box_left());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
width_here += extra_width_from_left_floats + extra_width_from_right_floats;
|
width_here += extra_width_from_left_floats + extra_width_from_right_floats;
|
||||||
|
|
|
@ -39,7 +39,7 @@ BlockFormattingContext const& InlineFormattingContext::parent() const
|
||||||
CSSPixels InlineFormattingContext::leftmost_x_offset_at(CSSPixels y) const
|
CSSPixels InlineFormattingContext::leftmost_x_offset_at(CSSPixels y) const
|
||||||
{
|
{
|
||||||
// NOTE: Floats are relative to the BFC root box, not necessarily the containing block of this IFC.
|
// NOTE: Floats are relative to the BFC root box, not necessarily the containing block of this IFC.
|
||||||
auto box_in_root_rect = content_box_rect_in_ancestor_coordinate_space(containing_block(), parent().root());
|
auto box_in_root_rect = content_box_rect_in_ancestor_coordinate_space(m_containing_block_state, parent().root());
|
||||||
CSSPixels y_in_root = box_in_root_rect.y() + y;
|
CSSPixels y_in_root = box_in_root_rect.y() + y;
|
||||||
auto space_and_containing_margin = parent().space_used_and_containing_margin_for_floats(y_in_root);
|
auto space_and_containing_margin = parent().space_used_and_containing_margin_for_floats(y_in_root);
|
||||||
auto left_side_floats_limit_to_right = space_and_containing_margin.left_total_containing_margin + space_and_containing_margin.left_used_space;
|
auto left_side_floats_limit_to_right = space_and_containing_margin.left_total_containing_margin + space_and_containing_margin.left_used_space;
|
||||||
|
@ -362,7 +362,7 @@ void InlineFormattingContext::generate_line_boxes(LayoutMode layout_mode)
|
||||||
|
|
||||||
bool InlineFormattingContext::any_floats_intrude_at_y(CSSPixels y) const
|
bool InlineFormattingContext::any_floats_intrude_at_y(CSSPixels y) const
|
||||||
{
|
{
|
||||||
auto box_in_root_rect = content_box_rect_in_ancestor_coordinate_space(containing_block(), parent().root());
|
auto box_in_root_rect = content_box_rect_in_ancestor_coordinate_space(m_containing_block_state, parent().root());
|
||||||
CSSPixels y_in_root = box_in_root_rect.y() + y;
|
CSSPixels y_in_root = box_in_root_rect.y() + y;
|
||||||
auto space_and_containing_margin = parent().space_used_and_containing_margin_for_floats(y_in_root);
|
auto space_and_containing_margin = parent().space_used_and_containing_margin_for_floats(y_in_root);
|
||||||
return space_and_containing_margin.left_used_space > 0 || space_and_containing_margin.right_used_space > 0;
|
return space_and_containing_margin.left_used_space > 0 || space_and_containing_margin.right_used_space > 0;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue