Repository: LadybirdBrowser/ladybird
File: Libraries/LibWeb/Layout/LayoutState.cpp (C++)

Code before:
                paintable_box->set_override_borders_data(used_values.override_borders_data().value());
            if (used_values.table_cell_coordinates().has_value())
                paintable_box->set_table_cell_coordinates(used_values.table_cell_coordinates().value());

            if (auto* paintable_with_lines = as_if<Painting::PaintableWithLines>(*paintable_box)) {
                for (size_t line_index = 0; line_index < used_values.line_boxes.size(); ++line_index) {
                    auto& line_box = used_values.line_boxes[line_index];
                    for (auto& fragment : line_box.fragments()) {
                        if (auto const* text_node = as_if<TextNode>(fragment.layout_node()))
                            text_nodes.set(const_cast<TextNode*>(text_node));
                        auto did_relocate_fragment = try_to_relocate_fragment_in_inline_node(fragment, line_index);
                        if (!did_relocate_fragment)
                            paintable_with_lines->add_fragment(fragment);
                    }
                }
            }

            if (used_values.computed_svg_transforms().has_value() && is<Painting::SVGGraphicsPaintable>(paintable_box)) {
                auto& svg_graphics_paintable = static_cast<Painting::SVGGraphicsPaintable&>(*paintable_box);
                svg_graphics_paintable.set_computed_transforms(*used_values.computed_svg_transforms());
            }

            if (used_values.computed_svg_path().has_value() && is<Painting::SVGPathPaintable>(paintable_box)) {
                auto& svg_geometry_paintable = static_cast<Painting::SVGPathPaintable&>(*paintable_box);
                svg_geometry_paintable.set_computed_path(move(*used_values.computed_svg_path()));
            }

            if (node.display().is_grid_inside()) {
                paintable_box->set_used_values_for_grid_template_columns(used_values.grid_template_columns());
                paintable_box->set_used_values_for_grid_template_rows(used_values.grid_template_rows());
            }
        }
    }

    // Create paintables for inline nodes without fragments to make possible querying their geometry.
    for (auto& inline_node : inline_nodes) {
        if (inline_node->first_paintable())
            continue;

        auto line_paintable = inline_node->create_paintable_for_line_with_index(0);
        inline_node->add_paintable(line_paintable);
        inline_node_paintables.set(line_paintable.ptr());
        if (auto const* used_values = used_values_per_layout_node.get(*inline_node).value_or(nullptr))
            transfer_box_model_metrics(line_paintable->box_model(), *used_values);
    }

    // Resolve relative positions for regular boxes (not line box fragments):
    // NOTE: This needs to occur before fragments are transferred into the corresponding inline paintables, because
    //       after this transfer, the containing_line_box_fragment will no longer be valid.
    for (auto& it : used_values_per_layout_node) {
        auto& used_values = *it.value;

Review comment (refactor):
You could simplify this slightly like this:
```c++
if (auto* svg_geometry_paintable = as_if<Painting::SVGGraphicsPaintable>(paintable_box)) {
    if (used_values.computed_svg_transforms().has_value()) {
        svg_geometry_paintable->set_computed_transforms(*used_values.computed_svg_transforms());
    }

    if (used_values.computed_svg_path().has_value()) {
        svg_geometry_paintable->set_computed_path(move(*used_values.computed_svg_path()));
    }
}
```

Code after:
                paintable_box->set_override_borders_data(used_values.override_borders_data().value());
            if (used_values.table_cell_coordinates().has_value())
                paintable_box->set_table_cell_coordinates(used_values.table_cell_coordinates().value());

            if (auto* paintable_with_lines = as_if<Painting::PaintableWithLines>(*paintable_box)) {
                for (size_t line_index = 0; line_index < used_values.line_boxes.size(); ++line_index) {
                    auto& line_box = used_values.line_boxes[line_index];
                    for (auto& fragment : line_box.fragments()) {
                        if (auto const* text_node = as_if<TextNode>(fragment.layout_node()))
                            text_nodes.set(const_cast<TextNode*>(text_node));
                        auto did_relocate_fragment = try_to_relocate_fragment_in_inline_node(fragment, line_index);
                        if (!did_relocate_fragment)
                            paintable_with_lines->add_fragment(fragment);
                    }
                }
            }

            if (auto* svg_graphics_paintable = as_if<Painting::SVGGraphicsPaintable>(paintable.ptr());
                svg_graphics_paintable && used_values.computed_svg_transforms().has_value()) {
                svg_graphics_paintable->set_computed_transforms(*used_values.computed_svg_transforms());
            }

            if (auto* svg_path_paintable = as_if<Painting::SVGPathPaintable>(paintable.ptr());
                svg_path_paintable && used_values.computed_svg_path().has_value()) {
                svg_path_paintable->set_computed_path(move(*used_values.computed_svg_path()));
            }

            if (node.display().is_grid_inside()) {
                paintable_box->set_used_values_for_grid_template_columns(used_values.grid_template_columns());
                paintable_box->set_used_values_for_grid_template_rows(used_values.grid_template_rows());
            }
        }
    }

    // Create paintables for inline nodes without fragments to make possible querying their geometry.
    for (auto& inline_node : inline_nodes) {
        if (inline_node->first_paintable())
            continue;

        auto line_paintable = inline_node->create_paintable_for_line_with_index(0);
        inline_node->add_paintable(line_paintable);
        inline_node_paintables.set(line_paintable.ptr());
        if (auto const* used_values = used_values_per_layout_node.get(*inline_node).value_or(nullptr))
            transfer_box_model_metrics(line_paintable->box_model(), *used_values);
    }

    // Resolve relative positions for regular boxes (not line box fragments):
    // NOTE: This needs to occur before fragments are transferred into the corresponding inline paintables, because
    //       after this transfer, the containing_line_box_fragment will no longer be valid.
    for (auto& it : used_values_per_layout_node) {
        auto& used_values = *it.value;