DescriptionCache element indices for :nth-child and :nth-last-child selectors.
In order to avoid n^2 for :nth-selectors, we introduce a cache where we
store the index of every kth child of a parent node P the first time the
nth-count is queried for one of its children. The number k is given by
the "spread" constant.
After the cache has been populated for the children of P, the nth-index
for an element will be found by walking the siblings from the element
queried for and leftwards until a cached element/index pair is found.
So populating the cache for P is O(n). Subsequent lookups are best case
O(1), worst case O(k).
The cache is created on the stack when we do operations where we know we
can benefit from having it. Currently, those are querySelector,
querySelectorAll, and updateStyle. We are throwing away the cache after
each operation to avoid holding on to potentially large caches in memory.
R=esprehn@chromium.org
BUG=461878
Committed: https://src.chromium.org/viewvc/blink?view=rev&revision=193268
Patch Set 1 #Patch Set 2 : Keep cache on Document, inlining, and tweaking spread. #Patch Set 3 : Oilpan tracing and removed unused nth-of-type. #Patch Set 4 : Wrote tests #Patch Set 5 : Split out include file fix #Patch Set 6 : Rebase and oilpan fixes #Patch Set 7 : Clear cache after each operation #
Total comments: 14
Patch Set 8 : Fixed review issues from sof #
Total comments: 2
Patch Set 9 : Moved nth-index-cache scope to updateStyle #
Total comments: 2
Patch Set 10 : Moved NthIndexCacheScope #
Total comments: 6
Patch Set 11 : More review issues #
Total comments: 3
Patch Set 12 : Back to stack-based cache #
Total comments: 9
Patch Set 13 : Review issues #Patch Set 14 : Rebased #Patch Set 15 : Store NthCacheIndex on Document #Patch Set 16 : Rebased #Patch Set 17 : Missing initializer and incorrect assert. #Messages
Total messages: 45 (13 generated)
|