1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 09:07:45 +00:00

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.
This commit is contained in:
Sam Atkins 2022-03-22 12:58:36 +00:00 committed by Andreas Kling
parent cbe2eaebab
commit 31b24c2b29
4 changed files with 3 additions and 30 deletions

View file

@ -105,8 +105,6 @@ u32 Selector::specificity() const
case SimpleSelector::Type::Universal:
// ignore the universal selector
break;
case SimpleSelector::Type::Invalid:
break;
}
}
}

View file

@ -21,7 +21,6 @@ using SelectorList = NonnullRefPtrVector<class Selector>;
class Selector : public RefCounted<Selector> {
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<Empty, Attribute, PseudoClass, PseudoElement, FlyString> value {};
Attribute const& attribute() const { return value.get<Attribute>(); }
@ -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();
}

View file

@ -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: