diff --git a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp index 4d2fd3a4e2..37cf614378 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp @@ -634,32 +634,29 @@ static NonnullRefPtr get_inherit_value(CSS::PropertyID property_id, { if (!element || !element->parent_element() || !element->parent_element()->specified_css_values()) return property_initial_value(property_id); - auto const& map = element->parent_element()->specified_css_values()->properties(); - auto it = map.find(property_id); - VERIFY(it != map.end()); - return *it->value; + return element->parent_element()->specified_css_values()->property(property_id).release_value(); }; void StyleComputer::compute_defaulted_property_value(StyleProperties& style, DOM::Element const* element, CSS::PropertyID property_id) const { // FIXME: If we don't know the correct initial value for a property, we fall back to InitialStyleValue. - auto it = style.m_property_values.find(property_id); - if (it == style.m_property_values.end()) { + auto& value_slot = style.m_property_values[to_underlying(property_id)]; + if (!value_slot) { if (is_inherited_property(property_id)) - style.m_property_values.set(property_id, get_inherit_value(property_id, element)); + style.m_property_values[to_underlying(property_id)] = get_inherit_value(property_id, element); else - style.m_property_values.set(property_id, property_initial_value(property_id)); + style.m_property_values[to_underlying(property_id)] = property_initial_value(property_id); return; } - if (it->value->is_initial()) { - it->value = property_initial_value(property_id); + if (value_slot->is_initial()) { + value_slot = property_initial_value(property_id); return; } - if (it->value->is_inherit()) { - it->value = get_inherit_value(property_id, element); + if (value_slot->is_inherit()) { + value_slot = get_inherit_value(property_id, element); return; } } @@ -869,8 +866,10 @@ void StyleComputer::absolutize_values(StyleProperties& style, DOM::Element const // FIXME: Get the root element font. float root_font_size = 10; - for (auto& it : style.properties()) { - it.value->visit_lengths([&](Length& length) { + for (auto& value_slot : style.m_property_values) { + if (!value_slot) + continue; + value_slot->visit_lengths([&](Length& length) { if (length.is_absolute() || length.is_relative()) { auto px = length.to_px(viewport_rect, font_metrics, root_font_size); length = Length::make_px(px); diff --git a/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp b/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp index 1ae062b8d1..97b10e1e6a 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp @@ -36,15 +36,15 @@ NonnullRefPtr StyleProperties::clone() const void StyleProperties::set_property(CSS::PropertyID id, NonnullRefPtr value) { - m_property_values.set(id, move(value)); + m_property_values[to_underlying(id)] = move(value); } Optional> StyleProperties::property(CSS::PropertyID property_id) const { - auto it = m_property_values.find(property_id); - if (it == m_property_values.end()) + auto value = m_property_values[to_underlying(property_id)]; + if (!value) return {}; - return it->value; + return value.release_nonnull(); } Length StyleProperties::length_or_fallback(CSS::PropertyID id, Length const& fallback) const @@ -390,12 +390,18 @@ bool StyleProperties::operator==(const StyleProperties& other) const if (m_property_values.size() != other.m_property_values.size()) return false; - for (auto& it : m_property_values) { - auto jt = other.m_property_values.find(it.key); - if (jt == other.m_property_values.end()) + for (size_t i = 0; i < m_property_values.size(); ++i) { + auto const& my_ptr = m_property_values[i]; + auto const& other_ptr = m_property_values[i]; + if (!my_ptr) { + if (other_ptr) + return false; + continue; + } + if (!other_ptr) return false; - auto& my_value = *it.value; - auto& other_value = *jt->value; + auto const& my_value = *my_ptr; + auto const& other_value = *other_ptr; if (my_value.type() != other_value.type()) return false; if (my_value != other_value) diff --git a/Userland/Libraries/LibWeb/CSS/StyleProperties.h b/Userland/Libraries/LibWeb/CSS/StyleProperties.h index f0790a04ac..d501619a32 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleProperties.h +++ b/Userland/Libraries/LibWeb/CSS/StyleProperties.h @@ -29,12 +29,14 @@ public: template inline void for_each_property(Callback callback) const { - for (auto& it : m_property_values) - callback((CSS::PropertyID)it.key, *it.value); + for (size_t i = 0; i < m_property_values.size(); ++i) { + if (m_property_values[i]) + callback((CSS::PropertyID)i, *m_property_values[i]); + } } - HashMap>& properties() { return m_property_values; } - HashMap> const& properties() const { return m_property_values; } + auto& properties() { return m_property_values; } + auto const& properties() const { return m_property_values; } void set_property(CSS::PropertyID, NonnullRefPtr value); Optional> property(CSS::PropertyID) const; @@ -96,7 +98,7 @@ public: private: friend class StyleComputer; - HashMap> m_property_values; + Array, to_underlying(CSS::last_property_id) + 1> m_property_values; Optional overflow(CSS::PropertyID) const; mutable RefPtr m_font;