mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-05-03 04:52:06 +02:00
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:
committed by
Jelle Raaijmakers
parent
4b556feecf
commit
a27d269721
Notes:
github-actions[bot]
2026-01-09 09:02:40 +00:00
Author: https://github.com/tcl3 Commit: https://github.com/LadybirdBrowser/ladybird/commit/a27d269721e Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/7381 Reviewed-by: https://github.com/gmta ✅
@@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user