mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-03 15:41:57 +00:00
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:
parent
385c3d273a
commit
c3d61020e7
Notes:
github-actions[bot]
2025-01-30 18:33:46 +00:00
Author: https://github.com/AtkinsSJ
Commit: c3d61020e7
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3383
7 changed files with 185 additions and 185 deletions
|
@ -116,7 +116,7 @@ static Optional<RoundingStrategy> parse_rounding_strategy(Vector<ComponentValue>
|
|||
return keyword_to_rounding_strategy(maybe_keyword.value());
|
||||
}
|
||||
|
||||
OwnPtr<CalculationNode> Parser::parse_math_function(Function const& function, CalculationContext const& context)
|
||||
RefPtr<CalculationNode> Parser::parse_math_function(Function const& function, CalculationContext const& context)
|
||||
{
|
||||
TokenStream stream { function.value };
|
||||
auto arguments = parse_a_comma_separated_list_of_component_values(stream);
|
||||
|
@ -137,7 +137,7 @@ OwnPtr<CalculationNode> Parser::parse_math_function(Function const& function, Ca
|
|||
// Variadic function
|
||||
function_generator.append(R"~~~(
|
||||
Optional<CSSNumericType> determined_argument_type;
|
||||
Vector<NonnullOwnPtr<CalculationNode>> parsed_arguments;
|
||||
Vector<NonnullRefPtr<CalculationNode>> parsed_arguments;
|
||||
parsed_arguments.ensure_capacity(arguments.size());
|
||||
|
||||
for (auto& argument : arguments) {
|
||||
|
@ -243,7 +243,7 @@ OwnPtr<CalculationNode> Parser::parse_math_function(Function const& function, Ca
|
|||
} else {
|
||||
// NOTE: This assumes everything not handled above is a calculation node of some kind.
|
||||
parameter_is_calculation = true;
|
||||
parameter_generator.set("parameter_type", "OwnPtr<CalculationNode>"_string);
|
||||
parameter_generator.set("parameter_type", "RefPtr<CalculationNode>"_string);
|
||||
parameter_generator.set("parse_function", "parse_a_calculation(arguments[argument_index], context)"_string);
|
||||
parameter_generator.set("check_function", " != nullptr"_string);
|
||||
parameter_generator.set("release_function", ".release_nonnull()"_string);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue