Module builder

Source
Expand description

Helper module to build up a selector safely and efficiently.

Our selector representation is designed to optimize matching, and has several requirements:

  • All simple selectors and combinators are stored inline in the same buffer as Component instances.
  • We store the top-level compound selectors from right to left, i.e. in matching order.
  • We store the simple selectors for each combinator from left to right, so that we match the cheaper simple selectors first.

For example, the selector:

.bar:hover > .baz:nth-child(2) + .qux

Gets stored as:

[.qux, + , .baz, :nth-child(2), > , .bar, :hover]

Meeting all these constraints without extra memmove traffic during parsing is non-trivial. This module encapsulates those details and presents an easy-to-use API for the parser.

Structsยง

ExactChain ๐Ÿ”’
SelectorBuilder
Top-level SelectorBuilder struct. This should be stack-allocated by the consumer and never moved (because it contains a lot of inline data that would be slow to memmove).
SelectorFlags ๐Ÿ”’
Flags that indicate at which point of parsing a selector are we.
Specificity ๐Ÿ”’
SpecificityAndFlags

Constantsยง

MAX_10BIT ๐Ÿ”’

Functionsยง

complex_selector_specificity_and_flags ๐Ÿ”’
relative_selector_list_specificity_and_flags ๐Ÿ”’
selector_list_specificity_and_flags ๐Ÿ”’
Finds the maximum specificity of elements in the list and returns it.
specificity_and_flags ๐Ÿ”’