Repository: LadybirdBrowser/ladybird
File: Libraries/LibWeb/CSS/StyleValues/BasicShapeStyleValue.cpp (C++)

Code before:
        };
        if (first)
            path.move_to(resolved_point);
        else
            path.line_to(resolved_point);
        first = false;
    }
    path.close();
    return path;
}

String Polygon::to_string(SerializationMode mode) const
{
    StringBuilder builder;
    switch (fill_rule) {
    case Gfx::WindingRule::Nonzero:
        break;
    case Gfx::WindingRule::EvenOdd:
        builder.append("evenodd"sv);
    }
    for (auto const& point : points) {
        if (!builder.is_empty())
            builder.append(", "sv);
        builder.appendff("{} {}", point.x->to_string(mode), point.y->to_string(mode));
    }
    return MUST(String::formatted("polygon({})", builder.to_string_without_validation()));
}

Gfx::Path Path::to_path(CSSPixelRect, Layout::Node const&) const
{
    auto result = path_instructions.to_gfx_path();
    result.set_fill_type(fill_rule);
    return result;
}

// https://drafts.csswg.org/css-shapes/#basic-shape-serialization
String Path::to_string(SerializationMode mode) const
{
    StringBuilder builder;
    builder.append("path("sv);

    // For serializing computed values, component values are computed, and omitted when possible without changing the meaning.
    // NB: So, we don't include `nonzero` in that case.
    if (!(mode == SerializationMode::ResolvedValue && fill_rule == Gfx::WindingRule::Nonzero)) {
        switch (fill_rule) {
        case Gfx::WindingRule::Nonzero:
            builder.append("nonzero, "sv);
            break;
        case Gfx::WindingRule::EvenOdd:
            builder.append("evenodd, "sv);
        }

Review comment (suggestion):
A bit of a nitpick since there are so many string allocations anyway, but could this be done in a way that avoids the extra string allocation introduced by `String::formatted()`? 

Would something like this work?
```diff
diff --git a/Libraries/LibWeb/CSS/StyleValues/BasicShapeStyleValue.cpp b/Libraries/LibWeb/CSS/StyleValues/BasicShapeStyleValue.cpp
index 64e2b6a49a6..290857c94b2 100644
--- a/Libraries/LibWeb/CSS/StyleValues/BasicShapeStyleValue.cpp
+++ b/Libraries/LibWeb/CSS/StyleValues/BasicShapeStyleValue.cpp
@@ -173,15 +173,22 @@ String Polygon::to_string(SerializationMode mode) const
 {
     StringBuilder builder;
     builder.append("polygon("sv);
+
+    bool first = true;
     switch (fill_rule) {
     case Gfx::WindingRule::Nonzero:
-        builder.append("nonzero"sv);
         break;
     case Gfx::WindingRule::EvenOdd:
         builder.append("evenodd"sv);
+        first = false;
+        break;
     }
+
     for (auto const& point : points) {
-        builder.appendff(", {} {}", point.x->to_string(mode), point.y->to_string(mode));
+        if (!first)
+            builder.append(", "sv);
+        first = false;
+        builder.appendff("{} {}", point.x->to_string(mode), point.y->to_string(mode));
     }
     builder.append(')');
     return MUST(builder.to_string());
```

Code after:
        };
        if (first)
            path.move_to(resolved_point);
        else
            path.line_to(resolved_point);
        first = false;
    }
    path.close();
    return path;
}

String Polygon::to_string(SerializationMode mode) const
{
    StringBuilder builder;
    builder.append("polygon("sv);
    bool first = true;
    switch (fill_rule) {
    case Gfx::WindingRule::Nonzero:
        break;
    case Gfx::WindingRule::EvenOdd:
        first = false;
        builder.append("evenodd"sv);
    }
    for (auto const& point : points) {
        if (!first)
            builder.append(", "sv);
        first = false;
        builder.appendff("{} {}", point.x->to_string(mode), point.y->to_string(mode));
    }
    builder.append(')');
    return builder.to_string_without_validation();
}

Gfx::Path Path::to_path(CSSPixelRect, Layout::Node const&) const
{
    auto result = path_instructions.to_gfx_path();
    result.set_fill_type(fill_rule);
    return result;
}

// https://drafts.csswg.org/css-shapes/#basic-shape-serialization
String Path::to_string(SerializationMode mode) const
{
    StringBuilder builder;
    builder.append("path("sv);

    // For serializing computed values, component values are computed, and omitted when possible without changing the meaning.
    // NB: So, we don't include `nonzero` in that case.
    if (!(mode == SerializationMode::ResolvedValue && fill_rule == Gfx::WindingRule::Nonzero)) {
        switch (fill_rule) {
        case Gfx::WindingRule::Nonzero: