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

@@ -8,18 +8,24 @@
namespace Web::CSS {
String TextUnderlinePositionStyleValue::to_string(SerializationMode) const
void TextUnderlinePositionStyleValue::serialize(StringBuilder& builder, SerializationMode) const
{
if (m_horizontal == TextUnderlinePositionHorizontal::Auto && m_vertical == TextUnderlinePositionVertical::Auto)
return "auto"_string;
if (m_horizontal == TextUnderlinePositionHorizontal::Auto && m_vertical == TextUnderlinePositionVertical::Auto) {
builder.append("auto"sv);
return;
}
if (m_vertical == TextUnderlinePositionVertical::Auto)
return MUST(String::from_utf8(CSS::to_string(m_horizontal)));
if (m_vertical == TextUnderlinePositionVertical::Auto) {
builder.append(CSS::to_string(m_horizontal));
return;
}
if (m_horizontal == TextUnderlinePositionHorizontal::Auto)
return MUST(String::from_utf8(CSS::to_string(m_vertical)));
if (m_horizontal == TextUnderlinePositionHorizontal::Auto) {
builder.append(CSS::to_string(m_vertical));
return;
}
return MUST(String::formatted("{} {}", CSS::to_string(m_horizontal), CSS::to_string(m_vertical)));
builder.appendff("{} {}", CSS::to_string(m_horizontal), CSS::to_string(m_vertical));
}
}