1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 07:17:35 +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: case SimpleSelector::Type::Universal:
// ignore the universal selector // ignore the universal selector
break; break;
case SimpleSelector::Type::Invalid:
break;
} }
} }
} }

View file

@ -21,7 +21,6 @@ using SelectorList = NonnullRefPtrVector<class Selector>;
class Selector : public RefCounted<Selector> { class Selector : public RefCounted<Selector> {
public: public:
enum class PseudoElement { enum class PseudoElement {
None,
Before, Before,
After, After,
FirstLine, FirstLine,
@ -32,7 +31,6 @@ public:
struct SimpleSelector { struct SimpleSelector {
enum class Type { enum class Type {
Invalid,
Universal, Universal,
TagName, TagName,
Id, Id,
@ -54,7 +52,6 @@ public:
struct PseudoClass { struct PseudoClass {
enum class Type { enum class Type {
None,
Link, Link,
Visited, Visited,
Hover, Hover,
@ -81,7 +78,7 @@ public:
Active, Active,
Lang, 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. // 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". // Only used when "pseudo_class" is "NthChild" or "NthLastChild".
@ -95,7 +92,6 @@ public:
struct Attribute { struct Attribute {
enum class MatchType { enum class MatchType {
None,
HasAttribute, HasAttribute,
ExactValueMatch, ExactValueMatch,
ContainsWord, // [att~=val] ContainsWord, // [att~=val]
@ -104,12 +100,12 @@ public:
StartsWithString, // [att^=val] StartsWithString, // [att^=val]
EndsWithString, // [att$=val] EndsWithString, // [att$=val]
}; };
MatchType match_type { MatchType::None }; MatchType match_type;
FlyString name {}; FlyString name {};
String value {}; String value {};
}; };
Type type { Type::Invalid }; Type type;
Variant<Empty, Attribute, PseudoClass, PseudoElement, FlyString> value {}; Variant<Empty, Attribute, PseudoClass, PseudoElement, FlyString> value {};
Attribute const& attribute() const { return value.get<Attribute>(); } 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; return "first-letter"sv;
case Selector::PseudoElement::Marker: case Selector::PseudoElement::Marker:
return "marker"sv; return "marker"sv;
case Selector::PseudoElement::None:
break;
} }
VERIFY_NOT_REACHED(); VERIFY_NOT_REACHED();
} }
@ -234,8 +228,6 @@ constexpr StringView pseudo_class_name(Selector::SimpleSelector::PseudoClass::Ty
return "where"sv; return "where"sv;
case Selector::SimpleSelector::PseudoClass::Type::Lang: case Selector::SimpleSelector::PseudoClass::Type::Lang:
return "lang"sv; return "lang"sv;
case Selector::SimpleSelector::PseudoClass::Type::None:
break;
} }
VERIFY_NOT_REACHED(); 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); return element.attribute(attribute.name).starts_with(attribute.value);
case CSS::Selector::SimpleSelector::Attribute::MatchType::EndsWithString: case CSS::Selector::SimpleSelector::Attribute::MatchType::EndsWithString:
return element.attribute(attribute.name).ends_with(attribute.value); return element.attribute(attribute.name).ends_with(attribute.value);
case CSS::Selector::SimpleSelector::Attribute::MatchType::None:
VERIFY_NOT_REACHED();
break;
} }
return false; 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) static inline bool matches_pseudo_class(CSS::Selector::SimpleSelector::PseudoClass const& pseudo_class, DOM::Element const& element)
{ {
switch (pseudo_class.type) { switch (pseudo_class.type) {
case CSS::Selector::SimpleSelector::PseudoClass::Type::None:
break;
case CSS::Selector::SimpleSelector::PseudoClass::Type::Link: case CSS::Selector::SimpleSelector::PseudoClass::Type::Link:
return element.is_link(); return element.is_link();
case CSS::Selector::SimpleSelector::PseudoClass::Type::Visited: case CSS::Selector::SimpleSelector::PseudoClass::Type::Visited:

View file

@ -333,9 +333,6 @@ void dump_selector(StringBuilder& builder, CSS::Selector const& selector)
auto& simple_selector = relative_selector.simple_selectors[i]; auto& simple_selector = relative_selector.simple_selectors[i];
char const* type_description = "Unknown"; char const* type_description = "Unknown";
switch (simple_selector.type) { switch (simple_selector.type) {
case CSS::Selector::SimpleSelector::Type::Invalid:
type_description = "Invalid";
break;
case CSS::Selector::SimpleSelector::Type::Universal: case CSS::Selector::SimpleSelector::Type::Universal:
type_description = "Universal"; type_description = "Universal";
break; break;
@ -378,9 +375,6 @@ void dump_selector(StringBuilder& builder, CSS::Selector const& selector)
case CSS::Selector::SimpleSelector::PseudoClass::Type::Active: case CSS::Selector::SimpleSelector::PseudoClass::Type::Active:
pseudo_class_description = "Active"; pseudo_class_description = "Active";
break; break;
case CSS::Selector::SimpleSelector::PseudoClass::Type::None:
pseudo_class_description = "None";
break;
case CSS::Selector::SimpleSelector::PseudoClass::Type::Root: case CSS::Selector::SimpleSelector::PseudoClass::Type::Root:
pseudo_class_description = "Root"; pseudo_class_description = "Root";
break; break;
@ -479,9 +473,6 @@ void dump_selector(StringBuilder& builder, CSS::Selector const& selector)
if (simple_selector.type == CSS::Selector::SimpleSelector::Type::PseudoElement) { if (simple_selector.type == CSS::Selector::SimpleSelector::Type::PseudoElement) {
char const* pseudo_element_description = ""; char const* pseudo_element_description = "";
switch (simple_selector.pseudo_element()) { switch (simple_selector.pseudo_element()) {
case CSS::Selector::PseudoElement::None:
pseudo_element_description = "NONE";
break;
case CSS::Selector::PseudoElement::Before: case CSS::Selector::PseudoElement::Before:
pseudo_element_description = "before"; pseudo_element_description = "before";
break; break;
@ -507,9 +498,6 @@ void dump_selector(StringBuilder& builder, CSS::Selector const& selector)
char const* attribute_match_type_description = ""; char const* attribute_match_type_description = "";
switch (attribute.match_type) { switch (attribute.match_type) {
case CSS::Selector::SimpleSelector::Attribute::MatchType::None:
attribute_match_type_description = "NONE";
break;
case CSS::Selector::SimpleSelector::Attribute::MatchType::HasAttribute: case CSS::Selector::SimpleSelector::Attribute::MatchType::HasAttribute:
attribute_match_type_description = "HasAttribute"; attribute_match_type_description = "HasAttribute";
break; break;