LibWeb: Make StyleProperties::m_property_values a bit smaller

Instead of wrapping every entry in Optional, use the null state of the
style pointer for the same purpose.

This shrinks StyleProperties by 1752 bytes per instance.
This commit is contained in:
Andreas Kling 2024-03-18 12:02:29 +01:00
commit 21bfa001b1
Notes: sideshowbarker 2024-07-17 02:55:44 +09:00
4 changed files with 44 additions and 50 deletions

View file

@ -47,12 +47,12 @@ NonnullRefPtr<StyleProperties> StyleProperties::clone() const
bool StyleProperties::is_property_important(CSS::PropertyID property_id) const
{
return m_property_values[to_underlying(property_id)].has_value() && m_property_values[to_underlying(property_id)]->important == Important::Yes;
return m_property_values[to_underlying(property_id)].style && m_property_values[to_underlying(property_id)].important == Important::Yes;
}
bool StyleProperties::is_property_inherited(CSS::PropertyID property_id) const
{
return m_property_values[to_underlying(property_id)].has_value() && m_property_values[to_underlying(property_id)]->inherited == Inherited::Yes;
return m_property_values[to_underlying(property_id)].style && m_property_values[to_underlying(property_id)].inherited == Inherited::Yes;
}
void StyleProperties::set_property(CSS::PropertyID id, NonnullRefPtr<StyleValue const> value, CSS::CSSStyleDeclaration const* source_declaration, Inherited inherited, Important important)
@ -75,26 +75,20 @@ NonnullRefPtr<StyleValue const> StyleProperties::property(CSS::PropertyID proper
if (auto animated_value = m_animated_property_values.get(property_id).value_or(nullptr))
return *animated_value;
auto value = m_property_values[to_underlying(property_id)];
// By the time we call this method, all properties have values assigned.
VERIFY(value.has_value());
return value->style;
return *m_property_values[to_underlying(property_id)].style;
}
RefPtr<StyleValue const> StyleProperties::maybe_null_property(CSS::PropertyID property_id) const
{
if (auto animated_value = m_animated_property_values.get(property_id).value_or(nullptr))
return *animated_value;
auto value = m_property_values[to_underlying(property_id)];
if (value.has_value())
return value->style;
return {};
return m_property_values[to_underlying(property_id)].style;
}
CSS::CSSStyleDeclaration const* StyleProperties::property_source_declaration(CSS::PropertyID property_id) const
{
return m_property_values[to_underlying(property_id)].map([](auto& value) { return value.declaration; }).value_or(nullptr);
return m_property_values[to_underlying(property_id)].declaration;
}
CSS::Size StyleProperties::size_value(CSS::PropertyID id) const
@ -628,15 +622,15 @@ bool StyleProperties::operator==(StyleProperties const& other) const
for (size_t i = 0; i < m_property_values.size(); ++i) {
auto const& my_style = m_property_values[i];
auto const& other_style = other.m_property_values[i];
if (!my_style.has_value()) {
if (other_style.has_value())
if (!my_style.style) {
if (other_style.style)
return false;
continue;
}
if (!other_style.has_value())
if (!other_style.style)
return false;
auto const& my_value = *my_style->style;
auto const& other_value = *other_style->style;
auto const& my_value = *my_style.style;
auto const& other_value = *other_style.style;
if (my_value.type() != other_value.type())
return false;
if (my_value != other_value)