LibWeb: Pass StringBuilder around during StyleValue serialization

Previously, some StyleValues created a large number of intermediate
strings during serialization. Passing a StringBUilder into the
serialization function allows us to avoid a large number of these
unnecessary allocations.
This commit is contained in:
Tim Ledbetter
2026-01-08 12:02:18 +00:00
committed by Jelle Raaijmakers
parent 4b556feecf
commit a27d269721
Notes: github-actions[bot] 2026-01-09 09:02:40 +00:00
136 changed files with 663 additions and 557 deletions

View File

@@ -9,23 +9,24 @@
namespace Web::CSS {
String BorderImageSliceStyleValue::to_string(SerializationMode mode) const
void BorderImageSliceStyleValue::serialize(StringBuilder& builder, SerializationMode mode) const
{
StringBuilder builder;
if (first_is_equal_to_all_of(top(), right(), bottom(), left())) {
builder.append(top()->to_string(mode));
} else if (top() == bottom() && right() == left()) {
builder.appendff("{} {}", top()->to_string(mode), right()->to_string(mode));
} else if (left() == right()) {
builder.appendff("{} {} {}", top()->to_string(mode), right()->to_string(mode), bottom()->to_string(mode));
} else {
builder.appendff("{} {} {} {}", top()->to_string(mode), right()->to_string(mode), bottom()->to_string(mode), left()->to_string(mode));
top()->serialize(builder, mode);
if (!first_is_equal_to_all_of(top(), right(), bottom(), left())) {
builder.append(' ');
right()->serialize(builder, mode);
if (top() != bottom() || right() != left()) {
builder.append(' ');
bottom()->serialize(builder, mode);
if (left() != right()) {
builder.append(' ');
left()->serialize(builder, mode);
}
}
}
if (fill())
builder.append(" fill"sv);
return MUST(builder.to_string());
}
}