Jelajahi Sumber

LibWeb: Include immediate child (>) combinator in ancestor filter

Before this change, the ancestor filter would only reject rules that
required a certain set of descendant strings (class, ID or tag name)
to be present in the current element's ancestor chain.

An immediate child is also a descendant, so we can include this
relationship in the ancestor filter as well.

This substantially improves the efficiency of the ancestor filter on
websites using Tailwind CSS.

For example, https://tailwindcss.com/ itself goes from full style
updates taking ~1400ms to ~350ms. Still *way* too long, but a huge
improvement nonetheless.
Andreas Kling 10 bulan lalu
induk
melakukan
34fdd0d44f
1 mengubah file dengan 1 tambahan dan 1 penghapusan
  1. 1 1
      Userland/Libraries/LibWeb/CSS/Selector.cpp

+ 1 - 1
Userland/Libraries/LibWeb/CSS/Selector.cpp

@@ -44,7 +44,7 @@ void Selector::collect_ancestor_hashes()
     auto last_combinator = m_compound_selectors.last().combinator;
     for (ssize_t compound_selector_index = static_cast<ssize_t>(m_compound_selectors.size()) - 2; compound_selector_index >= 0; --compound_selector_index) {
         auto const& compound_selector = m_compound_selectors[compound_selector_index];
-        if (last_combinator == Combinator::Descendant) {
+        if (last_combinator == Combinator::Descendant || last_combinator == Combinator::ImmediateChild) {
             for (auto const& simple_selector : compound_selector.simple_selectors) {
                 switch (simple_selector.type) {
                 case SimpleSelector::Type::Id: