- From: L. David Baron <dbaron@dbaron.org>
- Date: Sat, 20 Mar 2004 13:30:43 -0800
- To: www-style@w3.org
On Saturday 2004-03-20 16:05 -0500, Wilton Pyle wrote: > The beauty of a "-" selector is its simplicity. > The concept is easy to understand from a programmer's point of view, > referencing parents is a straightforward programming task. True. However, it's completely irrelevant to the issue here. In CSS style sheets, selectors are used for matching -- for each element, the implementation examines all the selectors, determines which ones match, and cascades the resulting declarations. (The matching process essentially reads the selector from end to beginning.) So implementation of a parent selector in that model requires, when looking at an element, examining *all* of its children (or, for an ancestor selector, all of its descendants). This is hard to do efficiently. It's especially hard when a page is loading and being displayed incrementally, since then some elements may be displayed with only a subset of their children, which may be added a few at a time. (Consider the body element in a typical HTML document.) It's also hard when the DOM is used to manipulate already-loaded pages, since it means any DOM manipulation would require examination of all the ancestors of the element being manipulated. A simple implementation would just rerun the selector matching process for all the ancestors -- which requires reexamining every node in the document (and many of them multiple times). In theory, this would need to happen for any DOM manipulation (including attribute change) or state (:hover/:active) change, although some such changes can be optimized away. In other words, the optimization required to make anything like this not be extremely slow is nowhere near trivial. The optimization required to make it work correctly and avoid making it not slow down pages that don't even use it at all is relatively simple, but not entirely trivial (by which I mean that it's a similar amount of work to implementing all the other combinators currently in CSS). I'd hesitate to call that "simplicity". > Actual implementation of, and consistancy between browsers, for a "-" > selector, is much more likely. As an implementor, I doubt it. -David -- L. David Baron <URL: http://dbaron.org/ >
Received on Saturday, 20 March 2004 16:31:15 UTC