Le 29/07/2013 20:06, Boris Zbarsky a écrit :
On 7/29/13 11:38 AM, Simon Sapin wrote:
      type Namespace = i32  // Is this some kind of interning as well?

In Gecko, yes.

* Use vectors / arrays instead of linked lists for AtomList,
PseudoClassList and SelectorList. (Less allocations) This could make it
more difficult to point somewhere in the middle of list (especially in
Rust), but I don’t know how important that is.

I don't think we generally need to point into the middle of those lists.

* Use a single optional string for an ID selector instead of a list. If
a (combinator-separated part in Selectors L4 spec terminology) "compound
selector" that has more than ID simple selector selector, either they
are all the same and we only need one string (#foo#foo is the same as
#foo), or they are different and the selector never matches.

#foo#foo has different specificity from #foo, so we need to keep track
of that.

And #foo#bar never matches, but still needs to be present in the CSSOM....

* Use a bit field for simple (non-functional) pseudo-classes. Same as ID
selectors, repeating the same pseudo-class does not change the selector.
(eg. :empty:empty is the same as :empty. This is true for all
pseudo-classes defined in Selectors 4 AFAIK.)

Again, except for specificity...

What if we store:

a. A CSS representation of the whole selector list a a string, for the CSSOM’s selectorText
b. The specificity for the cascade
c. Just the data structures we need for matching

I think this would work, but maybe the cost of a. cancels whatever we gain in c.?


So I think here are the main issues we have with Gecko's selectors, in
terms of your structs, that aren't discussed in your mail:

That is good to know, thanks.


1)  The linked list for SelectorList leads to lots of cache misses as we
traverse it, last we measured.

Would using a vector rather than a linked list fix that?


2)  The Selector struct is pretty large and most of the stuff in it is
unset for most selectors.  The vast majority of selectors are tag, id,
or class, with namespace almost always '*'.

How about, instead of a big Selector struct, having a "list of simple selectors"? This list does not have to be in CSS source order, it could be reordered in a way that makes matching more convenient (eg. ID selectors first.)

Something like this:


    type SelectorList = ~[Selector];

    struct Selector {
        compound_selectors: ~[CompoundSelector],
        pseudo_element: PseudoElement,
        specificity: u32,
        text: ~str,
    }

    struct CompoundSelector {
        simple_selectors: ~[SimpleSelector],
        combinator: Combinator,
    }

    enum SimpleSelector {
        IDSelector(Atom),
        ClassSelector(Atom),
        LocalNameSelector{lowercase_name: Atom, cased_name: Atom},
        NamespaceSelector(Namespace)

        // Attribute selectors
        AttrExists(AttrSelector),  // [foo]
        AttrEqual(AttrSelector, ~str),  // [foo=bar]
        AttrIncludes(AttrSelector, ~str),  // [foo~=bar]
        // ...

        // Pseudo-classes
        Empty,
        Root,
        Lang(Atom),
        NthChild(u32, u32),
        NthLastChild(u32, u32),
        Negation(~Selector),
        // ...
    }

    struct AttrSelector {
        lowercase_name: Atom,
        cased_name: Atom,
        namespace: Namespace,
    }


--
Simon Sapin
_______________________________________________
dev-servo mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-servo

Reply via email to