mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 07:48:11 +00:00
LibWeb: Make Layout::FormattingState copies shallow
Previously, each NodeState in a FormattingState was shared with the parent FormattingState, but the HashMap of NodeState had to be copied when making FormattingState copies. This patch makes copying instant by keeping a pointer to the parent FormattingState instead. When fetching immutable state via get(), we may now return a reference to a NodeState owned by a parent FormattingState. get_mutable() will copy any NodeState found in the ancestor chain before making a brand new one.
This commit is contained in:
parent
b6097cf724
commit
515db5fc1b
4 changed files with 40 additions and 30 deletions
|
@ -440,7 +440,7 @@ float FlexFormattingContext::calculate_indefinite_main_size(FlexItem const& item
|
|||
|
||||
if (has_definite_cross_size(item.box)) {
|
||||
// For indefinite main sizes, we perform a throwaway layout and then measure it.
|
||||
auto throwaway_state = m_state;
|
||||
FormattingState throwaway_state(&m_state);
|
||||
auto& box_state = throwaway_state.get_mutable(item.box);
|
||||
|
||||
// Item has definite cross size, layout with that as the used cross size.
|
||||
|
@ -470,7 +470,7 @@ float FlexFormattingContext::calculate_indefinite_main_size(FlexItem const& item
|
|||
// then layout with that and see what height comes out of it.
|
||||
float fit_content_cross_size = calculate_fit_content_width(item.box, m_available_space->cross);
|
||||
|
||||
auto throwaway_state = m_state;
|
||||
FormattingState throwaway_state(&m_state);
|
||||
auto& box_state = throwaway_state.get_mutable(item.box);
|
||||
|
||||
// Item has definite cross size, layout with that as the used cross size.
|
||||
|
@ -814,7 +814,7 @@ void FlexFormattingContext::determine_hypothetical_cross_size_of_item(FlexItem&
|
|||
|
||||
if (has_definite_main_size(item.box)) {
|
||||
// For indefinite cross sizes, we perform a throwaway layout and then measure it.
|
||||
auto throwaway_state = m_state;
|
||||
FormattingState throwaway_state(&m_state);
|
||||
auto& box_state = throwaway_state.get_mutable(item.box);
|
||||
|
||||
// Item has definite main size, layout with that as the used main size.
|
||||
|
@ -842,7 +842,7 @@ void FlexFormattingContext::determine_hypothetical_cross_size_of_item(FlexItem&
|
|||
else
|
||||
fit_content_main_size = calculate_fit_content_height(item.box, m_available_space->main);
|
||||
|
||||
auto throwaway_state = m_state;
|
||||
FormattingState throwaway_state(&m_state);
|
||||
auto& box_state = throwaway_state.get_mutable(item.box);
|
||||
|
||||
// Item has definite main size, layout with that as the used main size.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue