Vixen
02b45cc4
csharp
public sealed class RuleIndex

Which rules an element could possibly match, without testing them all.

No guide page documents this yet — the page shows what the code says about itself.

Remarks

Naive matching is O(elements × rules), and a real stylesheet has thousands of rules while a real panel has thousands of elements. The standard answer, and the one every browser uses: bucket each rule by the most selective thing in its rightmost compound — its id if it has one, else a class, else a tag — and give an element only the buckets its own id, classes and tag name reach. Thousands of candidates become single digits.

The rightmost compound is the right key precisely because matching runs right to left: it is the only part guaranteed to be tested against the element itself.

Rules whose rightmost compound names nothing — * > .x's tail, :hover on its own — go in a universal bucket every element gets. That bucket is the one to keep an eye on: a stylesheet whose rules mostly end in a bare pseudo-class has defeated the index, and UniversalCount is here so that is visible rather than merely slow.

Fields and properties (2)

  • public int Count

    How many rules have been indexed.

  • public int UniversalCount

    How many rules no bucket could narrow, and which every element must therefore test.

Methods (4)

  • public RuleIndex(SelectorTable table)

    Which rules an element could possibly match, without testing them all.

  • public Selector SelectorOf(int rule)

    The selector behind a rule index.

  • public int Add(Selector selector)

    Adds a rule.

  • public void Collect(StyleTree tree, StyleNodeId element, List<int> candidates)

    Collects the rules could match.

Used by (4)

  • SelectorOracleTestsVixen.Ui.Styling.Tests
  • StyleFixtureVixen.Ui.Styling.Tests
  • StyleResolverVixen.Ui.Styling
  • StyleRuleSetVixen.Ui.Styling