LibWeb/CSS: Make CalculationNodes ref-counted

Calc simplification (which I'm working towards) involves repeatedly
deriving a new calculation tree from an existing one, and in many
cases, either the whole result or a portion of it will be identical to
that of the original. Using RefPtr lets us avoid making unnecessary
copies. As a bonus it will also make it easier to return either `this`
or a new node.

In future we could also cache commonly-used nodes, similar to how we do
so for 1px and 0px LengthStyleValues and various keywords.
This commit is contained in:
Sam Atkins 2025-01-22 16:50:54 +00:00 committed by Andreas Kling
commit c3d61020e7
Notes: github-actions[bot] 2025-01-30 18:33:46 +00:00
7 changed files with 185 additions and 185 deletions

View file

@ -276,8 +276,8 @@ private:
RefPtr<CalculatedStyleValue> parse_calculated_value(ComponentValue const&);
RefPtr<CustomIdentStyleValue> parse_custom_ident_value(TokenStream<ComponentValue>&, std::initializer_list<StringView> blacklist);
// NOTE: Implemented in generated code. (GenerateCSSMathFunctions.cpp)
OwnPtr<CalculationNode> parse_math_function(Function const&, CalculationContext const&);
OwnPtr<CalculationNode> parse_a_calc_function_node(Function const&, CalculationContext const&);
RefPtr<CalculationNode> parse_math_function(Function const&, CalculationContext const&);
RefPtr<CalculationNode> parse_a_calc_function_node(Function const&, CalculationContext const&);
RefPtr<CSSStyleValue> parse_keyword_value(TokenStream<ComponentValue>&);
RefPtr<CSSStyleValue> parse_hue_none_value(TokenStream<ComponentValue>&);
RefPtr<CSSStyleValue> parse_solidus_and_alpha_value(TokenStream<ComponentValue>&);
@ -396,8 +396,8 @@ private:
RefPtr<CSSStyleValue> parse_grid_area_shorthand_value(TokenStream<ComponentValue>&);
RefPtr<CSSStyleValue> parse_grid_shorthand_value(TokenStream<ComponentValue>&);
OwnPtr<CalculationNode> convert_to_calculation_node(CalcParsing::Node const&, CalculationContext const&);
OwnPtr<CalculationNode> parse_a_calculation(Vector<ComponentValue> const&, CalculationContext const&);
RefPtr<CalculationNode> convert_to_calculation_node(CalcParsing::Node const&, CalculationContext const&);
RefPtr<CalculationNode> parse_a_calculation(Vector<ComponentValue> const&, CalculationContext const&);
ParseErrorOr<NonnullRefPtr<Selector>> parse_complex_selector(TokenStream<ComponentValue>&, SelectorType);
ParseErrorOr<Optional<Selector::CompoundSelector>> parse_compound_selector(TokenStream<ComponentValue>&);