Cache and reuse the HTMLFormElement.elements collection.
authorkling@webkit.org <kling@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 30 Dec 2011 20:15:16 +0000 (20:15 +0000)
committerkling@webkit.org <kling@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 30 Dec 2011 20:15:16 +0000 (20:15 +0000)
commitbe3e885947d130a55ccc78a8c11c780c42136765
treeb495c907f8574ed3a4fa259e17ad8be071480b62
parent46afec6784db1afadd50376068068f949031ad61
Cache and reuse the HTMLFormElement.elements collection.
<http://webkit.org/b/75375>

Reviewed by Anders Carlsson.

Source/WebCore:

Let HTMLFormElement::elements() cache the returned collection and tie it to the
lifetime of the form. This reduces memory consumption by ~70 kB (on 64-bit) when
viewing your average popular post on reddit.com.

Test: fast/dom/form-elements-collection-idempotence.html
      fast/dom/gc-9.html

* html/HTMLFormElement.h:
* html/HTMLFormElement.cpp:
(WebCore::HTMLFormElement::elements):

    Cache the HTMLFormCollection returned by elements() on the HTMLFormElement.
    Remove the per-form CollectionCache and let the collection manage that.

* html/HTMLCollection.h:
* html/HTMLCollection.cpp:
(WebCore::HTMLCollection::HTMLCollection):
(WebCore::HTMLCollection::create):

    Have the HTMLCollection constructor take a bool argument that decides whether
    we retain the base node pointer or not. This mechanism is a temporary measure
    until all collection types are owned by their respective base nodes.

* html/HTMLFormCollection.h:
* html/HTMLFormCollection.cpp:
(WebCore::HTMLFormCollection::HTMLFormCollection):
(WebCore::HTMLFormCollection::create):

    Tell the base class constructor to not retain the back-pointer to the form.

LayoutTests:

- Update gc-9.html to document the new lifetime characteristics of HTMLFormElement.elements.
- Add a test to verify that HTMLFormElement.elements returns the same object when called repeatedly.

* fast/dom/form-elements-collection-idempotence-expected.txt: Added.
* fast/dom/form-elements-collection-idempotence.html: Added.
* fast/dom/gc-9-expected.txt:
* fast/dom/gc-9.html:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@103848 268f45cc-cd09-0410-ab3c-d52691b4dbfc
12 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/dom/form-elements-collection-idempotence-expected.txt [new file with mode: 0644]
LayoutTests/fast/dom/form-elements-collection-idempotence.html [new file with mode: 0644]
LayoutTests/fast/dom/gc-9-expected.txt
LayoutTests/fast/dom/gc-9.html
Source/WebCore/ChangeLog
Source/WebCore/html/HTMLCollection.cpp
Source/WebCore/html/HTMLCollection.h
Source/WebCore/html/HTMLFormCollection.cpp
Source/WebCore/html/HTMLFormCollection.h
Source/WebCore/html/HTMLFormElement.cpp
Source/WebCore/html/HTMLFormElement.h