Bug 123823

Summary: Factor index cache for NodeLists and HTMLCollections to a class
Product: WebKit Reporter: Antti Koivisto <koivisto>
Component: DOMAssignee: Nobody <webkit-unassigned>
Status: RESOLVED FIXED    
Severity: Normal CC: buildbot, commit-queue, eflews.bot, esprehn+autocc, gyuyoung.kim, kangil.han, kling, rniwa
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
patch
rniwa: review+, eflews.bot: commit-queue-
Archive of layout-test-results from webkit-ews-13 for mac-mountainlion-wk2 none

Description Antti Koivisto 2013-11-05 13:20:33 PST
share code
Comment 1 Antti Koivisto 2013-11-05 13:34:25 PST
Created attachment 216071 [details]
patch
Comment 2 EFL EWS Bot 2013-11-05 13:42:24 PST
Comment on attachment 216071 [details]
patch

Attachment 216071 [details] did not pass efl-ews (efl):
Output: http://webkit-queues.appspot.com/results/21278006
Comment 3 EFL EWS Bot 2013-11-05 13:55:38 PST
Comment on attachment 216071 [details]
patch

Attachment 216071 [details] did not pass efl-wk2-ews (efl-wk2):
Output: http://webkit-queues.appspot.com/results/20998227
Comment 4 Ryosuke Niwa 2013-11-05 14:02:28 PST
Comment on attachment 216071 [details]
patch

View in context: https://bugs.webkit.org/attachment.cgi?id=216071&action=review

> Source/WebCore/dom/CollectionIndexCache.h:36
> +    unsigned size(const Collection&) const;

It's probably better call this length to match the terminology in HTMLCollection & NodeList.

> Source/WebCore/dom/CollectionIndexCache.h:46
> +    mutable unsigned m_cachedSize : 31;
> +    mutable unsigned m_cachedSizeValid : 1;

Ditto.

> Source/WebCore/dom/CollectionIndexCache.h:47
> +    mutable unsigned m_cachedCurrentPosition;

We should probably call this m_cachedCurrentIndex for consistency.

> Source/WebCore/dom/CollectionIndexCache.h:82
> +    if (index < m_cachedCurrentPosition - index) {
> +        // Start is closer to the target.

Instead of adding a comment, we can just define a bool as in:
const bool startIsCloserToTarget = index < m_cachedCurrentPosition - index;

> Source/WebCore/dom/CollectionIndexCache.h:104
> +    if (m_cachedSizeValid && m_cachedSize - index < index - m_cachedCurrentPosition) {
> +        // End is closer to the target.

Ditto.

> Source/WebCore/dom/CollectionIndexCache.h:129
> +    if (m_cachedSizeValid && index >= m_cachedSize)

We should assert that !m_cachedCurrentNode || index == m_cachedCurrentPosition.

> Source/WebCore/dom/CollectionIndexCache.h:138
> +    if (m_cachedSizeValid && m_cachedSize - index < index) {

Maybe we can define a boolean like:
const bool endIsCloserToTarget = m_cachedSizeValid && m_cachedSize - index < index;
?
Comment 5 Ryosuke Niwa 2013-11-05 14:04:49 PST
Also, you probably need to add the header to CMakeList.txt
Comment 6 Build Bot 2013-11-05 14:36:54 PST
Comment on attachment 216071 [details]
patch

Attachment 216071 [details] did not pass mac-wk2-ews (mac-wk2):
Output: http://webkit-queues.appspot.com/results/21288014

New failing tests:
dom/html/level2/html/HTMLIsIndexElement02.html
Comment 7 Build Bot 2013-11-05 14:36:56 PST
Created attachment 216081 [details]
Archive of layout-test-results from webkit-ews-13 for mac-mountainlion-wk2

The attached test failures were seen while running run-webkit-tests on the mac-wk2-ews.
Bot: webkit-ews-13  Port: mac-mountainlion-wk2  Platform: Mac OS X 10.8.5
Comment 8 Antti Koivisto 2013-11-05 15:44:51 PST
https://trac.webkit.org/r158698 (with a fix for failing test and stylistic changes)