Optimized querySelector(All) when selector contains #id.

There existed an optimization that did an element lookup for an id if the
leftmost part of the selector was an id selector. Without this change, these
queries would do an id lookup:

querySelector("#id"), querySelector("#id.class")

while these wouldn't:

querySelector(".class#id"), querySelector("[name=x]#id")

This change modifies the element lookup to include the latter two.

More importantly, it also extends the optimization for id selectors to limit
traversal of the dom-tree to the sub-tree rooted at the element with an id
matching the rightmost id selector in the whole selector. For id selectors
appearing left of adjacent combinators, the traversal needs to be rooted at
the parent of the element with the given id.

Examples:

querySelector("#id span") - traversal from the id element.
querySelector("#id + div span") - traversal from the parent of the id element.

This fix should make this:

querySelector("#id span")

as fast as:

getElementById("id").querySelector("span")

BUG=240188

Review URL: https://chromiumcodereview.appspot.com/14581013

git-svn-id: svn://svn.chromium.org/blink/trunk@150417 bbb929c8-8fbe-4397-9dbb-9b2b20218538
4 files changed
tree: eafb2b5d7cd8f27b431cbc493232dbe316677d8f
  1. third_party/