Optimized querySelector(All) when selector contains #id
authorbenjamin@webkit.org <benjamin@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 1 Mar 2014 22:09:48 +0000 (22:09 +0000)
committerbenjamin@webkit.org <benjamin@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 1 Mar 2014 22:09:48 +0000 (22:09 +0000)
commita382e17926db90144ad354fe1c5d094bc7169c6d
tree79f42afd11fe58b6b443ca21b51a5ab36d49d100
parent04057fd11d6790a34cbe2ecc9ad2fbf8c46adb3d
Optimized querySelector(All) when selector contains #id
https://bugs.webkit.org/show_bug.cgi?id=116502

Reviewed by Andreas Kling.

Source/WebCore:

Test: fast/selectors/querySelector-id-filtering.html

The idea of this patch is to perform querySelector on a subtree
rooted at the last element with #id matching. For example, if we have the selector
"#foobar div a", we start by looking for the element with ID foobar in the TreeScope
cache, and start matching the children from there.

The idea comes from Rune for
https://chromium.googlesource.com/chromium/blink/+/1cd83d3588973a02ab15d94b1b05a28620853624
but the code as diverged too much so it had to be reimplemented specifically for WebKit.

* css/CSSSelectorList.cpp:
(WebCore::CSSSelectorList::CSSSelectorList):
(WebCore::CSSSelectorList::operator=):
* css/CSSSelectorList.h:
(WebCore::CSSSelectorList::~CSSSelectorList):
* css/StyleRule.h:
(WebCore::StyleRule::wrapperAdoptSelectorList):
(WebCore::StyleRulePage::wrapperAdoptSelectorList):
* dom/SelectorQuery.cpp:
(WebCore::isSingleTagNameSelector):
(WebCore::isSingleClassNameSelector):
(WebCore::findIdMatchingType):
(WebCore::SelectorDataList::SelectorDataList):
(WebCore::filterRootById):
(WebCore::SelectorDataList::executeCompiledSimpleSelectorChecker):
(WebCore::SelectorDataList::execute):
(WebCore::SelectorQuery::SelectorQuery):
(WebCore::SelectorQueryCache::add):
* dom/SelectorQuery.h:
(WebCore::SelectorDataList::SelectorData::SelectorData):

LayoutTests:

* fast/selectors/querySelector-id-filtering-expected.txt: Added.
* fast/selectors/querySelector-id-filtering.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@164924 268f45cc-cd09-0410-ab3c-d52691b4dbfc
LayoutTests/ChangeLog
LayoutTests/fast/selectors/querySelector-id-filtering-expected.txt [new file with mode: 0644]
LayoutTests/fast/selectors/querySelector-id-filtering.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/css/CSSSelectorList.cpp
Source/WebCore/css/CSSSelectorList.h
Source/WebCore/css/StyleRule.h
Source/WebCore/dom/SelectorQuery.cpp
Source/WebCore/dom/SelectorQuery.h