Bug 123895 - Move array position caching out from HTMLCollection
Summary: Move array position caching out from HTMLCollection
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: DOM (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-11-06 08:37 PST by Antti Koivisto
Modified: 2013-11-06 10:17 PST (History)
2 users (show)

See Also:


Attachments
patch (21.39 KB, patch)
2013-11-06 08:54 PST, Antti Koivisto
darin: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Antti Koivisto 2013-11-06 08:37:53 PST
This caching complicated the logic but is used by a single subclass (HTMLFormControlsCollection) only. The subclass can do the caching itself.
Comment 1 Antti Koivisto 2013-11-06 08:54:03 PST
Created attachment 216180 [details]
patch
Comment 2 Darin Adler 2013-11-06 09:33:40 PST
Comment on attachment 216180 [details]
patch

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

> Source/WebCore/html/HTMLCollection.cpp:134
> +HTMLCollection::HTMLCollection(ContainerNode& ownerNode, CollectionType type, ElementTraversalType traversalType)

I think that the enum is great for the argument.

> Source/WebCore/html/HTMLCollection.cpp:144
> +    , m_elementTraversalType(traversalType)

But for the local, I might suggest we use a boolean named m_requiresCustomForwardTraversal or something like that.

In other words, I liked the readability of the old pattern where the data member was a boolean.

> Source/WebCore/html/HTMLCollection.h:76
> +    Element* traverseFirstElement(ContainerNode* root) const;

Nothing new, but I am not a big fan of the name “traverse first element”. The meaning of traverse here is unclear.

> Source/WebCore/html/HTMLCollection.h:143
> +    virtual Element* virtualElementAfter(Element*) const { ASSERT_NOT_REACHED(); return nullptr; }

So we can’t use pure virtual because we only need this for classes that are CustomForwardOnlyTraversal. Ugly.

> Source/WebCore/html/HTMLFormControlsCollection.cpp:77
> +    unsigned i = 0;
> +    for (; i < elementVector.size(); ++i) {
> +        auto& associatedElement = *elementVector[i];
> +        if (associatedElement.isEnumeratable() && &associatedElement.asHTMLElement() == &element)
> +            break;
> +    }
> +    return i;

I would put the return inside the loop, and use a normal for loop without an “outside the loop” i variable. I think that would also make it slightly clearer what the function returns when nothing is found. But maybe this is more elegant.
Comment 3 Antti Koivisto 2013-11-06 10:17:22 PST
http://trac.webkit.org/changeset/158758