From 31b24c2b297f603856b4850fb9568b5b91a75621 Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Tue, 22 Mar 2022 12:58:36 +0000 Subject: [PATCH] LibWeb: Remove now-unused null values from Selector enums Now that we use a Variant for the SimpleSelector's data, we don't need to instantiate empty structs or variables for the types that aren't used, and so we can remove `PseudoElement::None`, `PsuedoClass::Type::None` and `Attribute::MatchType::None`. Also, we now always initialize a SimpleSelector with a type, so `SimpleSelector::Type::Invalid` can go too. --- Userland/Libraries/LibWeb/CSS/Selector.cpp | 2 -- Userland/Libraries/LibWeb/CSS/Selector.h | 14 +++----------- Userland/Libraries/LibWeb/CSS/SelectorEngine.cpp | 5 ----- Userland/Libraries/LibWeb/Dump.cpp | 12 ------------ 4 files changed, 3 insertions(+), 30 deletions(-) diff --git a/Userland/Libraries/LibWeb/CSS/Selector.cpp b/Userland/Libraries/LibWeb/CSS/Selector.cpp index f995728a97..98115e71c4 100644 --- a/Userland/Libraries/LibWeb/CSS/Selector.cpp +++ b/Userland/Libraries/LibWeb/CSS/Selector.cpp @@ -105,8 +105,6 @@ u32 Selector::specificity() const case SimpleSelector::Type::Universal: // ignore the universal selector break; - case SimpleSelector::Type::Invalid: - break; } } } diff --git a/Userland/Libraries/LibWeb/CSS/Selector.h b/Userland/Libraries/LibWeb/CSS/Selector.h index 6893bf083a..14f65fd95e 100644 --- a/Userland/Libraries/LibWeb/CSS/Selector.h +++ b/Userland/Libraries/LibWeb/CSS/Selector.h @@ -21,7 +21,6 @@ using SelectorList = NonnullRefPtrVector; class Selector : public RefCounted { public: enum class PseudoElement { - None, Before, After, FirstLine, @@ -32,7 +31,6 @@ public: struct SimpleSelector { enum class Type { - Invalid, Universal, TagName, Id, @@ -54,7 +52,6 @@ public: struct PseudoClass { enum class Type { - None, Link, Visited, Hover, @@ -81,7 +78,7 @@ public: Active, Lang, }; - Type type { Type::None }; + Type type; // FIXME: We don't need this field on every single SimpleSelector, but it's also annoying to malloc it somewhere. // Only used when "pseudo_class" is "NthChild" or "NthLastChild". @@ -95,7 +92,6 @@ public: struct Attribute { enum class MatchType { - None, HasAttribute, ExactValueMatch, ContainsWord, // [att~=val] @@ -104,12 +100,12 @@ public: StartsWithString, // [att^=val] EndsWithString, // [att$=val] }; - MatchType match_type { MatchType::None }; + MatchType match_type; FlyString name {}; String value {}; }; - Type type { Type::Invalid }; + Type type; Variant value {}; Attribute const& attribute() const { return value.get(); } @@ -173,8 +169,6 @@ constexpr StringView pseudo_element_name(Selector::PseudoElement pseudo_element) return "first-letter"sv; case Selector::PseudoElement::Marker: return "marker"sv; - case Selector::PseudoElement::None: - break; } VERIFY_NOT_REACHED(); } @@ -234,8 +228,6 @@ constexpr StringView pseudo_class_name(Selector::SimpleSelector::PseudoClass::Ty return "where"sv; case Selector::SimpleSelector::PseudoClass::Type::Lang: return "lang"sv; - case Selector::SimpleSelector::PseudoClass::Type::None: - break; } VERIFY_NOT_REACHED(); } diff --git a/Userland/Libraries/LibWeb/CSS/SelectorEngine.cpp b/Userland/Libraries/LibWeb/CSS/SelectorEngine.cpp index 63025d40f8..504e44eae4 100644 --- a/Userland/Libraries/LibWeb/CSS/SelectorEngine.cpp +++ b/Userland/Libraries/LibWeb/CSS/SelectorEngine.cpp @@ -95,9 +95,6 @@ static inline bool matches_attribute(CSS::Selector::SimpleSelector::Attribute co return element.attribute(attribute.name).starts_with(attribute.value); case CSS::Selector::SimpleSelector::Attribute::MatchType::EndsWithString: return element.attribute(attribute.name).ends_with(attribute.value); - case CSS::Selector::SimpleSelector::Attribute::MatchType::None: - VERIFY_NOT_REACHED(); - break; } return false; @@ -124,8 +121,6 @@ static inline DOM::Element const* next_sibling_with_same_tag_name(DOM::Element c static inline bool matches_pseudo_class(CSS::Selector::SimpleSelector::PseudoClass const& pseudo_class, DOM::Element const& element) { switch (pseudo_class.type) { - case CSS::Selector::SimpleSelector::PseudoClass::Type::None: - break; case CSS::Selector::SimpleSelector::PseudoClass::Type::Link: return element.is_link(); case CSS::Selector::SimpleSelector::PseudoClass::Type::Visited: diff --git a/Userland/Libraries/LibWeb/Dump.cpp b/Userland/Libraries/LibWeb/Dump.cpp index e3e6e94a45..e65226e467 100644 --- a/Userland/Libraries/LibWeb/Dump.cpp +++ b/Userland/Libraries/LibWeb/Dump.cpp @@ -333,9 +333,6 @@ void dump_selector(StringBuilder& builder, CSS::Selector const& selector) auto& simple_selector = relative_selector.simple_selectors[i]; char const* type_description = "Unknown"; switch (simple_selector.type) { - case CSS::Selector::SimpleSelector::Type::Invalid: - type_description = "Invalid"; - break; case CSS::Selector::SimpleSelector::Type::Universal: type_description = "Universal"; break; @@ -378,9 +375,6 @@ void dump_selector(StringBuilder& builder, CSS::Selector const& selector) case CSS::Selector::SimpleSelector::PseudoClass::Type::Active: pseudo_class_description = "Active"; break; - case CSS::Selector::SimpleSelector::PseudoClass::Type::None: - pseudo_class_description = "None"; - break; case CSS::Selector::SimpleSelector::PseudoClass::Type::Root: pseudo_class_description = "Root"; break; @@ -479,9 +473,6 @@ void dump_selector(StringBuilder& builder, CSS::Selector const& selector) if (simple_selector.type == CSS::Selector::SimpleSelector::Type::PseudoElement) { char const* pseudo_element_description = ""; switch (simple_selector.pseudo_element()) { - case CSS::Selector::PseudoElement::None: - pseudo_element_description = "NONE"; - break; case CSS::Selector::PseudoElement::Before: pseudo_element_description = "before"; break; @@ -507,9 +498,6 @@ void dump_selector(StringBuilder& builder, CSS::Selector const& selector) char const* attribute_match_type_description = ""; switch (attribute.match_type) { - case CSS::Selector::SimpleSelector::Attribute::MatchType::None: - attribute_match_type_description = "NONE"; - break; case CSS::Selector::SimpleSelector::Attribute::MatchType::HasAttribute: attribute_match_type_description = "HasAttribute"; break;