diff --git a/Libraries/LibWeb/DOM/Element.cpp b/Libraries/LibWeb/DOM/Element.cpp index 85fbfc90dc..6b546b97c3 100644 --- a/Libraries/LibWeb/DOM/Element.cpp +++ b/Libraries/LibWeb/DOM/Element.cpp @@ -97,14 +97,10 @@ void Element::set_attributes(Vector&& attributes) parse_attribute(attribute.name(), attribute.value()); } -bool Element::has_class(const StringView& class_name) const +bool Element::has_class(const FlyString& class_name) const { - auto value = attribute("class"); - if (value.is_empty()) - return false; - auto parts = value.split_view(' '); - for (auto& part : parts) { - if (part == class_name) + for (auto& class_ : m_classes) { + if (class_ == class_name) return true; } return false; @@ -140,8 +136,16 @@ RefPtr Element::create_layout_node(const StyleProperties* parent_sty return adopt(*new LayoutInline(*this, move(style))); } -void Element::parse_attribute(const FlyString&, const String&) +void Element::parse_attribute(const FlyString& name, const String& value) { + if (name == "class") { + auto new_classes = value.split_view(' '); + m_classes.clear(); + m_classes.ensure_capacity(new_classes.size()); + for (auto& new_class : new_classes) { + m_classes.unchecked_append(new_class); + } + } } enum class StyleDifference { diff --git a/Libraries/LibWeb/DOM/Element.h b/Libraries/LibWeb/DOM/Element.h index 70c9d83f6b..7fbf3ab394 100644 --- a/Libraries/LibWeb/DOM/Element.h +++ b/Libraries/LibWeb/DOM/Element.h @@ -58,7 +58,7 @@ public: callback(attribute.name(), attribute.value()); } - bool has_class(const StringView&) const; + bool has_class(const FlyString&) const; virtual void apply_presentational_hints(StyleProperties&) const { } virtual void parse_attribute(const FlyString& name, const String& value); @@ -86,6 +86,8 @@ private: Vector m_attributes; RefPtr m_resolved_style; + + Vector m_classes; }; template<>