Repository: LadybirdBrowser/ladybird
File: Libraries/LibWeb/DOM/Element.h (C/C++)

Code before:

    CSSPixelPoint m_scroll_offset;

    bool m_in_top_layer : 1 { false };
    bool m_rendered_in_top_layer : 1 { false };
    bool m_style_uses_attr_css_function : 1 { false };
    bool m_style_uses_var_css_function : 1 { false };
    bool m_style_uses_tree_counting_function : 1 { false };
    bool m_child_style_uses_tree_counting_function : 1 { false };
    bool m_affected_by_has_pseudo_class_in_subject_position : 1 { false };
    bool m_affected_by_has_pseudo_class_in_non_subject_position : 1 { false };
    bool m_affected_by_direct_sibling_combinator : 1 { false };
    bool m_affected_by_indirect_sibling_combinator : 1 { false };
    bool m_affected_by_sibling_position_or_count_pseudo_class : 1 { false };
    bool m_affected_by_nth_child_pseudo_class : 1 { false };
    bool m_affected_by_has_pseudo_class_with_relative_selector_that_has_sibling_combinator : 1 { false };

    size_t m_sibling_invalidation_distance { 0 };

    OwnPtr<CSS::CountersSet> m_counters_set;

    // https://html.spec.whatwg.org/multipage/grouping-content.html#ordinal-value
    Optional<i32> m_ordinal_value;

    mutable Optional<String> m_lang_value;
    void invalidate_lang_value();

    // https://w3c.github.io/webappsec-csp/#is-element-nonceable
    // AD-HOC: We need to know the element had a duplicate attribute when it was created from the HTML parser.
    //         However, there currently isn't any specified way to do this, so we store a flag on the token, which is
    //         then passed down to here. This is used by Content Security Policy to disable the nonce attribute if this
    //         flag is set.
    bool m_had_duplicate_attribute_during_tokenization { false };

    // https://dom.spec.whatwg.org/#concept-element-custom-element-state
    CustomElementState m_custom_element_state { CustomElementState::Undefined };

    // https://drafts.csswg.org/css-contain/#proximity-to-the-viewport
    ProximityToTheViewport m_proximity_to_the_viewport { ProximityToTheViewport::NotDetermined };

    // https://drafts.csswg.org/css-view-transitions-1/#captured-in-a-view-transition
    bool m_captured_in_a_view_transition { false };

    bool m_is_contained_in_list_subtree { false };
};

template<>
inline bool Node::fast_is<Element>() const { return is_element(); }

inline GC::Ptr<Element> Node::parent_element()
{

Review comment (performance):
We have some logic that sets the document's pragma-set default language when a `<meta http-equiv="content-language">` element is inserted, which should also invalidate this new cache. Probably call `invalidate_lang_value()` on the document element?

Code after:
    GC::Ptr<CSS::StylePropertyMapReadOnly> m_computed_style_map_cache;

    CSSPixelPoint m_scroll_offset;

    bool m_in_top_layer : 1 { false };
    bool m_rendered_in_top_layer : 1 { false };
    bool m_style_uses_attr_css_function : 1 { false };
    bool m_style_uses_var_css_function : 1 { false };
    bool m_style_uses_tree_counting_function : 1 { false };
    bool m_child_style_uses_tree_counting_function : 1 { false };
    bool m_affected_by_has_pseudo_class_in_subject_position : 1 { false };
    bool m_affected_by_has_pseudo_class_in_non_subject_position : 1 { false };
    bool m_affected_by_direct_sibling_combinator : 1 { false };
    bool m_affected_by_indirect_sibling_combinator : 1 { false };
    bool m_affected_by_sibling_position_or_count_pseudo_class : 1 { false };
    bool m_affected_by_nth_child_pseudo_class : 1 { false };
    bool m_affected_by_has_pseudo_class_with_relative_selector_that_has_sibling_combinator : 1 { false };

    size_t m_sibling_invalidation_distance { 0 };

    OwnPtr<CSS::CountersSet> m_counters_set;

    // https://html.spec.whatwg.org/multipage/grouping-content.html#ordinal-value
    Optional<i32> m_ordinal_value;

    mutable Optional<String> m_lang_value;

    // https://w3c.github.io/webappsec-csp/#is-element-nonceable
    // AD-HOC: We need to know the element had a duplicate attribute when it was created from the HTML parser.
    //         However, there currently isn't any specified way to do this, so we store a flag on the token, which is
    //         then passed down to here. This is used by Content Security Policy to disable the nonce attribute if this
    //         flag is set.
    bool m_had_duplicate_attribute_during_tokenization { false };

    // https://dom.spec.whatwg.org/#concept-element-custom-element-state
    CustomElementState m_custom_element_state { CustomElementState::Undefined };

    // https://drafts.csswg.org/css-contain/#proximity-to-the-viewport
    ProximityToTheViewport m_proximity_to_the_viewport { ProximityToTheViewport::NotDetermined };

    // https://drafts.csswg.org/css-view-transitions-1/#captured-in-a-view-transition
    bool m_captured_in_a_view_transition { false };

    bool m_is_contained_in_list_subtree { false };
};

template<>
inline bool Node::fast_is<Element>() const { return is_element(); }

inline GC::Ptr<Element> Node::parent_element()
{