LibWeb: Use shortest serialization for shorthands with repeated values

For shorthands where all the values are repeated, we now only output
the value once.
This commit is contained in:
Tim Ledbetter 2025-03-20 10:58:38 +00:00 committed by Jelle Raaijmakers
commit 54351e7327
Notes: github-actions[bot] 2025-03-20 13:32:03 +00:00
8 changed files with 81 additions and 30 deletions

View file

@ -396,6 +396,17 @@ String ShorthandStyleValue::to_string(SerializationMode mode) const
return builder.to_string_without_validation();
}
default:
auto all_properties_same_value = true;
auto first_property_value = m_properties.values.first();
for (auto i = 1u; i < m_properties.values.size(); ++i) {
if (m_properties.values[i] != first_property_value) {
all_properties_same_value = false;
break;
}
}
if (all_properties_same_value)
return first_property_value->to_string(mode);
StringBuilder builder;
auto first = true;
for (auto& value : m_properties.values) {