Wow, it's now super clear. Thanks for the detailed explanation.

Just a quick follow up question to quench my curiosity: if I do "list[1]" and 
no one has ever asked the list for any element, Gecko will find the first two 
matching elements, and store them in the list, if I then immediately do 
"list[0]", the first element is returned without walking the DOM (assuming 
there are at least two matching elements)? 

> querySelector("foo") and getElementsByTagName("foo")[0] can return different 
> nodes

Still a bit confused regarding this. If the premise is the selector only 
contains characters allowed in a tag name, how can they return different nodes, 
maybe I missed something? Unless you mean querySelector(":foo") and 
getElementsByTagName(":foo")[0] can return different results, which is obvious.

If by parsing the passed selector (or lookup the cached parsed selectors) you 
know it only contains a tag name, why it is a bit harder to optimize? You just 
look up the (tagname, root) hash table, no?

> In practice this hasn't come up as a bottleneck in anything we've profiled so 
> far

I'm probably prematurely optimizing my code. But nevertheless learned something 
quite valuable by asking. Thanks for answering it. :)

Reply via email to