Move the remaining collections to caching on their respective base nodes.
authorkling@webkit.org <kling@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 1 Jan 2012 21:05:42 +0000 (21:05 +0000)
committerkling@webkit.org <kling@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 1 Jan 2012 21:05:42 +0000 (21:05 +0000)
<http://webkit.org/b/75416>

Reviewed by Anders Carlsson.

Source/WebCore:

Add a (lazily-allocated) array of HTMLCollections to ElementRareData and cache
the various collections on their base node rather than recreating them every time.

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

* html/CollectionType.h:
* dom/ElementRareData.h:
(WebCore::ElementRareData::hasCachedHTMLCollections):
(WebCore::ElementRareData::cachedHTMLCollection):
(WebCore::ElementRareData::ensureCachedHTMLCollection):
* dom/Element.h:
* dom/Element.cpp:
(WebCore::Element::ensureCachedHTMLCollection):

    Plumbing to cache HTMLCollections on ElementRareData.

(WebCore::Element::~Element):

    Detach any cached collections from an element when it's destroyed.

* html/HTMLCollection.h:
* html/HTMLCollection.cpp:
(WebCore::HTMLCollection::HTMLCollection):
(WebCore::HTMLCollection::create):
(WebCore::HTMLCollection::~HTMLCollection):
(WebCore::HTMLCollection::detachFromNode):
* html/HTMLTableRowsCollection.cpp:
(WebCore::HTMLTableRowsCollection::HTMLTableRowsCollection):
* html/HTMLOptionsCollection.cpp:
(WebCore::HTMLOptionsCollection::HTMLOptionsCollection):
* html/HTMLFormCollection.cpp:
(WebCore::HTMLFormCollection::HTMLFormCollection):
* dom/Document.cpp:
(WebCore::Document::cachedCollection):

    Consolidate the HTMLCollection constructors and get rid of the hacks to
    optionally retain the base node.

* html/HTMLDataListElement.cpp:
(WebCore::HTMLDataListElement::options):
* html/HTMLElement.cpp:
(WebCore::HTMLElement::children):
* html/HTMLMapElement.cpp:
(WebCore::HTMLMapElement::areas):
* html/HTMLTableElement.cpp:
(WebCore::HTMLTableElement::tBodies):
* html/HTMLTableRowElement.cpp:
(WebCore::HTMLTableRowElement::cells):
* html/HTMLTableSectionElement.cpp:
(WebCore::HTMLTableSectionElement::rows):

    Cached collections!

LayoutTests:

- Updated gc-9.html to document the new lifetime behavior of HTMLCollections.
- Merged all the *collection-idempotence.html tests into a big one and added
  tests for the newly changed collections.

* fast/dom/gc-9-expected.txt:
* fast/dom/gc-9.html:
* fast/dom/collection-idempotence-expected.txt: Added.
* fast/dom/collection-idempotence.html: Added.
* fast/dom/document-collection-idempotence-expected.txt: Removed.
* fast/dom/document-collection-idempotence.html: Removed.
* fast/dom/form-elements-collection-idempotence-expected.txt: Removed.
* fast/dom/form-elements-collection-idempotence.html: Removed.
* fast/dom/select-options-collection-idempotence-expected.txt: Removed.
* fast/dom/select-options-collection-idempotence.html: Removed.
* fast/dom/table-rows-collection-idempotence-expected.txt: Removed.
* fast/dom/table-rows-collection-idempotence.html: Removed.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@103883 268f45cc-cd09-0410-ab3c-d52691b4dbfc

29 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/dom/collection-idempotence-expected.txt [new file with mode: 0644]
LayoutTests/fast/dom/collection-idempotence.html [new file with mode: 0644]
LayoutTests/fast/dom/document-collection-idempotence-expected.txt [deleted file]
LayoutTests/fast/dom/document-collection-idempotence.html [deleted file]
LayoutTests/fast/dom/form-elements-collection-idempotence-expected.txt [deleted file]
LayoutTests/fast/dom/form-elements-collection-idempotence.html [deleted file]
LayoutTests/fast/dom/select-options-collection-idempotence-expected.txt [deleted file]
LayoutTests/fast/dom/select-options-collection-idempotence.html [deleted file]
LayoutTests/fast/dom/table-rows-collection-idempotence-expected.txt [deleted file]
LayoutTests/fast/dom/table-rows-collection-idempotence.html [deleted file]
Source/WebCore/ChangeLog
Source/WebCore/dom/Document.cpp
Source/WebCore/dom/Element.cpp
Source/WebCore/dom/Element.h
Source/WebCore/dom/ElementRareData.h
Source/WebCore/html/CollectionType.h
Source/WebCore/html/HTMLCollection.cpp
Source/WebCore/html/HTMLCollection.h
Source/WebCore/html/HTMLDataListElement.cpp
Source/WebCore/html/HTMLElement.cpp
Source/WebCore/html/HTMLFormCollection.cpp
Source/WebCore/html/HTMLMapElement.cpp
Source/WebCore/html/HTMLNameCollection.cpp
Source/WebCore/html/HTMLOptionsCollection.cpp
Source/WebCore/html/HTMLTableElement.cpp
Source/WebCore/html/HTMLTableRowElement.cpp
Source/WebCore/html/HTMLTableRowsCollection.cpp
Source/WebCore/html/HTMLTableSectionElement.cpp

index b84bc31..736a8bc 100644 (file)
@@ -1,3 +1,27 @@
+2012-01-01  Andreas Kling  <awesomekling@apple.com>
+
+        Move the remaining collections to caching on their respective base nodes.
+        <http://webkit.org/b/75416>
+
+        Reviewed by Anders Carlsson.
+
+        - Updated gc-9.html to document the new lifetime behavior of HTMLCollections.
+        - Merged all the *collection-idempotence.html tests into a big one and added
+          tests for the newly changed collections.
+
+        * fast/dom/gc-9-expected.txt:
+        * fast/dom/gc-9.html:
+        * fast/dom/collection-idempotence-expected.txt: Added.
+        * fast/dom/collection-idempotence.html: Added.
+        * fast/dom/document-collection-idempotence-expected.txt: Removed.
+        * fast/dom/document-collection-idempotence.html: Removed.
+        * fast/dom/form-elements-collection-idempotence-expected.txt: Removed.
+        * fast/dom/form-elements-collection-idempotence.html: Removed.
+        * fast/dom/select-options-collection-idempotence-expected.txt: Removed.
+        * fast/dom/select-options-collection-idempotence.html: Removed.
+        * fast/dom/table-rows-collection-idempotence-expected.txt: Removed.
+        * fast/dom/table-rows-collection-idempotence.html: Removed.
+
 2012-01-01  Balazs Kelemen  <kbalazs@webkit.org>
 
         [Qt] Layout divergence between WK1/2 in table tests
diff --git a/LayoutTests/fast/dom/collection-idempotence-expected.txt b/LayoutTests/fast/dom/collection-idempotence-expected.txt
new file mode 100644 (file)
index 0000000..5832380
--- /dev/null
@@ -0,0 +1,37 @@
+This test verifies that collection getters return the same collection when called repeatedly.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS document.all is document.all
+PASS document.all === document.all is true
+PASS document.images is document.images
+PASS document.images === document.images is true
+PASS document.embeds is document.embeds
+PASS document.embeds === document.embeds is true
+PASS document.applets is document.applets
+PASS document.applets === document.applets is true
+PASS document.links is document.links
+PASS document.links === document.links is true
+PASS document.forms is document.forms
+PASS document.forms === document.forms is true
+PASS document.anchors is document.anchors
+PASS document.anchors === document.anchors is true
+PASS document.scripts is document.scripts
+PASS document.scripts === document.scripts is true
+PASS document.getElementsByTagName('table')[0].rows[0].cells is document.getElementsByTagName('table')[0].rows[0].cells
+PASS document.getElementsByTagName('table')[0].rows[0].cells === document.getElementsByTagName('table')[0].rows[0].cells is true
+PASS document.getElementsByTagName('table')[0].tBodies is document.getElementsByTagName('table')[0].tBodies
+PASS document.getElementsByTagName('table')[0].tBodies === document.getElementsByTagName('table')[0].tBodies is true
+PASS document.getElementsByTagName('table')[0].tBodies[0].rows is document.getElementsByTagName('table')[0].tBodies[0].rows
+PASS document.getElementsByTagName('table')[0].tBodies[0].rows === document.getElementsByTagName('table')[0].tBodies[0].rows is true
+PASS document.body.children is document.body.children
+PASS document.body.children === document.body.children is true
+PASS document.getElementsByTagName('map')[0].areas is document.getElementsByTagName('map')[0].areas
+PASS document.getElementsByTagName('map')[0].areas === document.getElementsByTagName('map')[0].areas is true
+PASS document.getElementsByTagName('select')[0].options is document.getElementsByTagName('select')[0].options
+PASS document.getElementsByTagName('select')[0].options === document.getElementsByTagName('select')[0].options is true
+PASS successfullyParsed is true
+
+TEST COMPLETE
diff --git a/LayoutTests/fast/dom/collection-idempotence.html b/LayoutTests/fast/dom/collection-idempotence.html
new file mode 100644 (file)
index 0000000..3345000
--- /dev/null
@@ -0,0 +1,40 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="utf-8">
+<script src="../js/resources/js-test-pre.js"></script>
+</head>
+<body>
+<table><tr><td></td></tr></table>
+<map><area></area></map>
+<select><option></option></select>
+<script>
+
+description("This test verifies that collection getters return the same collection when called repeatedly.");
+
+var collections = [
+    "document.all",
+    "document.images",
+    "document.embeds",
+    "document.applets",
+    "document.links",
+    "document.forms",
+    "document.anchors",
+    "document.scripts",
+    "document.getElementsByTagName('table')[0].rows[0].cells",
+    "document.getElementsByTagName('table')[0].tBodies",
+    "document.getElementsByTagName('table')[0].tBodies[0].rows",
+    "document.body.children",
+    "document.getElementsByTagName('map')[0].areas",
+    "document.getElementsByTagName('select')[0].options"
+];
+
+for (var i = 0; i < collections.length; ++i) {
+    shouldBe(collections[i], collections[i]);
+    shouldBeTrue(collections[i] + " === " + collections[i]);
+}
+
+</script>
+<script src="../js/resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/fast/dom/document-collection-idempotence-expected.txt b/LayoutTests/fast/dom/document-collection-idempotence-expected.txt
deleted file mode 100644 (file)
index 11f225d..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-This test verifies that the HTMLCollection getters on document return the same object when called repeatedly.
-
-On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
-
-
-PASS document.all === document.all is true
-PASS document.images === document.images is true
-PASS document.embeds === document.embeds is true
-PASS document.plugins === document.plugins is true
-PASS document.applets === document.applets is true
-PASS document.links === document.links is true
-PASS document.forms === document.forms is true
-PASS document.anchors === document.anchors is true
-PASS document.scripts === document.scripts is true
-PASS successfullyParsed is true
-
-TEST COMPLETE
-
diff --git a/LayoutTests/fast/dom/document-collection-idempotence.html b/LayoutTests/fast/dom/document-collection-idempotence.html
deleted file mode 100644 (file)
index 0e2342b..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-<!DOCTYPE html>
-<html>
-<head>
-<meta charset="utf-8">
-<script src="../js/resources/js-test-pre.js"></script>
-</head>
-<body>
-<script>
-
-description("This test verifies that the HTMLCollection getters on document return the same object when called repeatedly.");
-
-var collections = [ "all", "images", "embeds", "plugins", "applets", "links", "forms", "anchors", "scripts" ];
-
-for (i = 0; i < collections.length; ++i) {
-    var collection = collections[i];
-    shouldBe("document." + collection + " === document." + collection, "true");
-}
-
-</script>
-<script src="../js/resources/js-test-post.js"></script>
-</body>
-</html>
diff --git a/LayoutTests/fast/dom/form-elements-collection-idempotence-expected.txt b/LayoutTests/fast/dom/form-elements-collection-idempotence-expected.txt
deleted file mode 100644 (file)
index ddec5e7..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-This test verifies that HTMLFormElement.elements returns the same collection when called repeatedly.
-
-On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
-
-
-PASS formElement.elements is formElement.elements
-PASS formElement.elements === formElement.elements is true
-PASS successfullyParsed is true
-
-TEST COMPLETE
-
diff --git a/LayoutTests/fast/dom/form-elements-collection-idempotence.html b/LayoutTests/fast/dom/form-elements-collection-idempotence.html
deleted file mode 100644 (file)
index ebbe54c..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-<!DOCTYPE html>
-<html>
-<head>
-<meta charset="utf-8">
-<script src="../js/resources/js-test-pre.js"></script>
-</head>
-<body>
-<script>
-
-description("This test verifies that HTMLFormElement.elements returns the same collection when called repeatedly.");
-
-var formElement = document.createElement("form");
-
-shouldBe("formElement.elements", "formElement.elements");
-shouldBeTrue("formElement.elements === formElement.elements");
-
-</script>
-<script src="../js/resources/js-test-post.js"></script>
-</body>
-</html>
diff --git a/LayoutTests/fast/dom/select-options-collection-idempotence-expected.txt b/LayoutTests/fast/dom/select-options-collection-idempotence-expected.txt
deleted file mode 100644 (file)
index faf503f..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-This test verifies that HTMLSelectElement.options returns the same collection when called repeatedly.
-
-On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
-
-
-PASS selectElement.options is selectElement.options
-PASS selectElement.options === selectElement.options is true
-PASS successfullyParsed is true
-
-TEST COMPLETE
-
diff --git a/LayoutTests/fast/dom/select-options-collection-idempotence.html b/LayoutTests/fast/dom/select-options-collection-idempotence.html
deleted file mode 100644 (file)
index 582a548..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-<!DOCTYPE html>
-<html>
-<head>
-<meta charset="utf-8">
-<script src="../js/resources/js-test-pre.js"></script>
-</head>
-<body>
-<script>
-
-description("This test verifies that HTMLSelectElement.options returns the same collection when called repeatedly.");
-
-var selectElement = document.createElement("select");
-
-shouldBe("selectElement.options", "selectElement.options");
-shouldBeTrue("selectElement.options === selectElement.options");
-
-</script>
-<script src="../js/resources/js-test-post.js"></script>
-</body>
-</html>
diff --git a/LayoutTests/fast/dom/table-rows-collection-idempotence-expected.txt b/LayoutTests/fast/dom/table-rows-collection-idempotence-expected.txt
deleted file mode 100644 (file)
index 7f0acf1..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-This test verifies that HTMLTableElement.rows returns the same collection when called repeatedly.
-
-On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
-
-
-PASS tableElement.rows is tableElement.rows
-PASS tableElement.rows === tableElement.rows is true
-PASS successfullyParsed is true
-
-TEST COMPLETE
-
diff --git a/LayoutTests/fast/dom/table-rows-collection-idempotence.html b/LayoutTests/fast/dom/table-rows-collection-idempotence.html
deleted file mode 100644 (file)
index 2df50a5..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-<!DOCTYPE html>
-<html>
-<head>
-<meta charset="utf-8">
-<script src="../js/resources/js-test-pre.js"></script>
-</head>
-<body>
-<script>
-
-description("This test verifies that HTMLTableElement.rows returns the same collection when called repeatedly.");
-
-var tableElement = document.createElement("table");
-
-shouldBe("tableElement.rows", "tableElement.rows");
-shouldBeTrue("tableElement.rows === tableElement.rows");
-
-</script>
-<script src="../js/resources/js-test-post.js"></script>
-</body>
-</html>
index 7fe8b4c..24d6796 100644 (file)
@@ -1,3 +1,64 @@
+2012-01-01  Andreas Kling  <awesomekling@apple.com>
+
+        Move the remaining collections to caching on their respective base nodes.
+        <http://webkit.org/b/75416>
+
+        Reviewed by Anders Carlsson.
+
+        Add a (lazily-allocated) array of HTMLCollections to ElementRareData and cache
+        the various collections on their base node rather than recreating them every time.
+
+        Test: fast/dom/collection-idempotence.html
+              fast/dom/gc-9.html
+
+        * html/CollectionType.h:
+        * dom/ElementRareData.h:
+        (WebCore::ElementRareData::hasCachedHTMLCollections):
+        (WebCore::ElementRareData::cachedHTMLCollection):
+        (WebCore::ElementRareData::ensureCachedHTMLCollection):
+        * dom/Element.h:
+        * dom/Element.cpp:
+        (WebCore::Element::ensureCachedHTMLCollection):
+
+            Plumbing to cache HTMLCollections on ElementRareData.
+
+        (WebCore::Element::~Element):
+
+            Detach any cached collections from an element when it's destroyed.
+
+        * html/HTMLCollection.h:
+        * html/HTMLCollection.cpp:
+        (WebCore::HTMLCollection::HTMLCollection):
+        (WebCore::HTMLCollection::create):
+        (WebCore::HTMLCollection::~HTMLCollection):
+        (WebCore::HTMLCollection::detachFromNode):
+        * html/HTMLTableRowsCollection.cpp:
+        (WebCore::HTMLTableRowsCollection::HTMLTableRowsCollection):
+        * html/HTMLOptionsCollection.cpp:
+        (WebCore::HTMLOptionsCollection::HTMLOptionsCollection):
+        * html/HTMLFormCollection.cpp:
+        (WebCore::HTMLFormCollection::HTMLFormCollection):
+        * dom/Document.cpp:
+        (WebCore::Document::cachedCollection):
+
+            Consolidate the HTMLCollection constructors and get rid of the hacks to
+            optionally retain the base node.
+
+        * html/HTMLDataListElement.cpp:
+        (WebCore::HTMLDataListElement::options):
+        * html/HTMLElement.cpp:
+        (WebCore::HTMLElement::children):
+        * html/HTMLMapElement.cpp:
+        (WebCore::HTMLMapElement::areas):
+        * html/HTMLTableElement.cpp:
+        (WebCore::HTMLTableElement::tBodies):
+        * html/HTMLTableRowElement.cpp:
+        (WebCore::HTMLTableRowElement::cells):
+        * html/HTMLTableSectionElement.cpp:
+        (WebCore::HTMLTableSectionElement::rows):
+
+            Cached collections!
+
 2012-01-01  Raymond Liu  <raymond.liu@intel.com>
 
         Use overload methods to implement [Optional] parameters in AudioNode.idl
index 2a43f05..ab50b1e 100644 (file)
@@ -4203,7 +4203,7 @@ const RefPtr<HTMLCollection>& Document::cachedCollection(CollectionType type)
 {
     ASSERT(static_cast<unsigned>(type) < NumUnnamedDocumentCachedTypes);
     if (!m_collections[type])
-        m_collections[type] = HTMLCollection::createForCachingOnDocument(this, type);
+        m_collections[type] = HTMLCollection::create(this, type);
     return m_collections[type];
 }
 
index 9936664..9679b12 100644 (file)
@@ -43,6 +43,7 @@
 #include "FocusController.h"
 #include "Frame.h"
 #include "FrameView.h"
+#include "HTMLCollection.h"
 #include "HTMLDocument.h"
 #include "HTMLElement.h"
 #include "HTMLFrameOwnerElement.h"
@@ -122,6 +123,16 @@ Element::~Element()
     removeShadowRoot();
     if (m_attributeMap)
         m_attributeMap->detachFromElement();
+
+    if (hasRareData()) {
+        ElementRareData* elementRareData = rareData();
+        if (elementRareData->hasCachedHTMLCollections()) {
+            for (unsigned type = 0; type < NumNodeCollectionTypes; ++type) {
+                if (HTMLCollection* collection = elementRareData->cachedHTMLCollection(static_cast<CollectionType>(FirstNodeCollectionType + type)))
+                    collection->detachFromNode();
+            }
+        }
+    }
 }
 
 inline ElementRareData* Element::rareData() const
@@ -2032,4 +2043,9 @@ void Element::updateExtraNamedItemRegistration(const AtomicString& oldId, const
         static_cast<HTMLDocument*>(document())->addExtraNamedItem(newId);
 }
 
+HTMLCollection* Element::ensureCachedHTMLCollection(CollectionType type)
+{
+    return ensureRareData()->ensureCachedHTMLCollection(this, type);
+}
+
 } // namespace WebCore
index 2b38a63..3925ba1 100644 (file)
@@ -25,6 +25,7 @@
 #ifndef Element_h
 #define Element_h
 
+#include "CollectionType.h"
 #include "Document.h"
 #include "FragmentScriptingPermission.h"
 #include "HTMLNames.h"
@@ -393,6 +394,8 @@ protected:
     
     void idAttributeChanged(Attribute*);
 
+    HTMLCollection* ensureCachedHTMLCollection(CollectionType);
+
 private:
     void scrollByUnits(int units, ScrollGranularity);
 
index 1caccd4..c5cf6cd 100644 (file)
@@ -25,6 +25,7 @@
 #include "ClassList.h"
 #include "DatasetDOMStringMap.h"
 #include "Element.h"
+#include "HTMLCollection.h"
 #include "NodeRareData.h"
 #include <wtf/OwnPtr.h>
 
@@ -42,6 +43,32 @@ public:
     using NodeRareData::needsFocusAppearanceUpdateSoonAfterAttach;
     using NodeRareData::setNeedsFocusAppearanceUpdateSoonAfterAttach;
 
+    typedef FixedArray<RefPtr<HTMLCollection>, NumNodeCollectionTypes> CachedHTMLCollectionArray;
+
+    bool hasCachedHTMLCollections() const
+    {
+        return m_cachedCollections;
+    }
+
+    HTMLCollection* cachedHTMLCollection(CollectionType type) const
+    {
+        ASSERT(m_cachedCollections);
+        return (*m_cachedCollections)[type - FirstNodeCollectionType].get();
+    }
+
+    HTMLCollection* ensureCachedHTMLCollection(Element* element, CollectionType type)
+    {
+        if (!m_cachedCollections)
+            m_cachedCollections = adoptPtr(new CachedHTMLCollectionArray);
+
+        RefPtr<HTMLCollection>& collection = (*m_cachedCollections)[type - FirstNodeCollectionType];
+        if (!collection)
+            collection = HTMLCollection::create(element, type);
+        return collection.get();
+    }
+
+    OwnPtr<CachedHTMLCollectionArray> m_cachedCollections;
+
     LayoutSize m_minimumSizeForResizing;
     RefPtr<RenderStyle> m_computedStyle;
     ShadowRoot* m_shadowRoot;
index 43c47fe..fa348f9 100644 (file)
@@ -38,7 +38,6 @@ enum CollectionType {
     DocScripts,   // all <script> elements
 
     DocAll,       // "all" elements (IE)
-    NodeChildren, // first-level children (IE)
 
     // named collection types cached in the document
 
@@ -47,6 +46,7 @@ enum CollectionType {
 
     // types not cached in the document; these are types that can't be used on a document
 
+    NodeChildren, // first-level children (IE)
     TableTBodies, // all <tbody> elements in this table
     TSectionRows, // all row elements in this table section
     TRCells,      // all cells in this row
@@ -62,7 +62,10 @@ enum CollectionType {
 };
 
 static const CollectionType FirstUnnamedDocumentCachedType = DocImages;
-static const unsigned NumUnnamedDocumentCachedTypes = NodeChildren - DocImages + 1;
+static const unsigned NumUnnamedDocumentCachedTypes = WindowNamedItems - DocImages + 1;
+
+static const CollectionType FirstNodeCollectionType = NodeChildren;
+static const unsigned NumNodeCollectionTypes = OtherCollection - NodeChildren + 1;
 
 } // namespace
 
index f7aed50..0d3f8f2 100644 (file)
@@ -37,26 +37,13 @@ namespace WebCore {
 
 using namespace HTMLNames;
 
-HTMLCollection::HTMLCollection(Document* document, CollectionType type)
-    : m_baseIsRetained(false)
-    , m_includeChildren(shouldIncludeChildren(type))
-    , m_ownsInfo(false)
-    , m_type(type)
-    , m_base(document)
-    , m_info(0)
-{
-}
-
-HTMLCollection::HTMLCollection(Node* base, CollectionType type, bool retainBaseNode)
-    : m_baseIsRetained(retainBaseNode)
-    , m_includeChildren(shouldIncludeChildren(type))
+HTMLCollection::HTMLCollection(Node* base, CollectionType type)
+    : m_includeChildren(shouldIncludeChildren(type))
     , m_ownsInfo(false)
     , m_type(type)
     , m_base(base)
     , m_info(0)
 {
-    if (m_baseIsRetained)
-        m_base->ref();
 }
 
 bool HTMLCollection::shouldIncludeChildren(CollectionType type)
@@ -91,28 +78,20 @@ bool HTMLCollection::shouldIncludeChildren(CollectionType type)
     return false;
 }
 
-PassRefPtr<HTMLCollection> HTMLCollection::createForCachingOnDocument(Document* document, CollectionType type)
-{
-    return adoptRef(new HTMLCollection(document, type));
-}
-
-PassRefPtr<HTMLCollection> HTMLCollection::create(PassRefPtr<Node> base, CollectionType type)
+PassRefPtr<HTMLCollection> HTMLCollection::create(Node* base, CollectionType type)
 {
-    return adoptRef(new HTMLCollection(base.get(), type));
+    return adoptRef(new HTMLCollection(base, type));
 }
 
 HTMLCollection::~HTMLCollection()
 {
     if (m_ownsInfo)
         delete m_info;
-    if (m_baseIsRetained)
-        m_base->deref();
 }
 
 void HTMLCollection::detachFromNode()
 {
     m_base = 0;
-    m_baseIsRetained = false;
 }
 
 void HTMLCollection::resetCollectionInfo() const
index 4f9370c..1bca3d3 100644 (file)
@@ -40,10 +40,9 @@ struct CollectionCache;
 
 class HTMLCollection : public RefCounted<HTMLCollection> {
 public:
-    static PassRefPtr<HTMLCollection> create(PassRefPtr<Node> base, CollectionType);
-    static PassRefPtr<HTMLCollection> createForCachingOnDocument(Document*, CollectionType);
+    static PassRefPtr<HTMLCollection> create(Node* base, CollectionType);
     virtual ~HTMLCollection();
-    
+
     unsigned length() const;
     
     virtual Node* item(unsigned index) const;
@@ -64,8 +63,7 @@ public:
     void detachFromNode();
 
 protected:
-    HTMLCollection(Node* base, CollectionType, bool retainBaseNode = true);
-    HTMLCollection(Document*, CollectionType);
+    HTMLCollection(Node* base, CollectionType);
 
     CollectionCache* info() const { return m_info; }
     void resetCollectionInfo() const;
@@ -81,7 +79,6 @@ private:
 
     bool isAcceptableElement(Element*) const;
 
-    bool m_baseIsRetained : 1;
     bool m_includeChildren : 1;
     mutable bool m_ownsInfo : 1;
     unsigned m_type : 5; // CollectionType
index b73606d..964d342 100644 (file)
@@ -49,7 +49,7 @@ PassRefPtr<HTMLDataListElement> HTMLDataListElement::create(const QualifiedName&
 
 PassRefPtr<HTMLCollection> HTMLDataListElement::options()
 {
-    return HTMLCollection::create(this, DataListOptions);
+    return ensureCachedHTMLCollection(DataListOptions);
 }
 
 }  // namespace WebCore
index 23e2945..bacd44f 100644 (file)
@@ -827,7 +827,7 @@ void HTMLElement::setTabIndex(int value)
 
 PassRefPtr<HTMLCollection> HTMLElement::children()
 {
-    return HTMLCollection::create(this, NodeChildren);
+    return ensureCachedHTMLCollection(NodeChildren);
 }
 
 bool HTMLElement::rendererIsNeeded(const NodeRenderingContext& context)
index c92ec6c..db63693 100644 (file)
@@ -37,7 +37,7 @@ using namespace HTMLNames;
 // calculation every time if anything has changed.
 
 HTMLFormCollection::HTMLFormCollection(HTMLFormElement* form)
-    : HTMLCollection(form, OtherCollection, /* retainBaseNode */ false)
+    : HTMLCollection(form, OtherCollection)
 {
 }
 
index 9db1542..098295b 100644 (file)
@@ -128,7 +128,7 @@ void HTMLMapElement::parseMappedAttribute(Attribute* attribute)
 
 PassRefPtr<HTMLCollection> HTMLMapElement::areas()
 {
-    return HTMLCollection::create(this, MapAreas);
+    return ensureCachedHTMLCollection(MapAreas);
 }
 
 void HTMLMapElement::insertedIntoDocument()
index 051dd90..ad73d32 100644 (file)
@@ -33,7 +33,7 @@ namespace WebCore {
 using namespace HTMLNames;
 
 HTMLNameCollection::HTMLNameCollection(Document* document, CollectionType type, const AtomicString& name)
-    : HTMLCollection(document, type, /* retainBaseNode */ false)
+    : HTMLCollection(document, type)
     , m_name(name)
 {
 }
index 7876d96..fea385e 100644 (file)
@@ -29,7 +29,7 @@
 namespace WebCore {
 
 HTMLOptionsCollection::HTMLOptionsCollection(HTMLSelectElement* select)
-    : HTMLCollection(select, SelectOptions, /* retainBaseNode */ false)
+    : HTMLCollection(select, SelectOptions)
 {
 }
 
index dd9494e..b6a4a5a 100644 (file)
@@ -633,7 +633,7 @@ PassRefPtr<HTMLCollection> HTMLTableElement::rows()
 
 PassRefPtr<HTMLCollection> HTMLTableElement::tBodies()
 {
-    return HTMLCollection::create(this, TableTBodies);
+    return ensureCachedHTMLCollection(TableTBodies);
 }
 
 String HTMLTableElement::rules() const
index fbc253d..5ec3bce 100644 (file)
@@ -156,7 +156,7 @@ void HTMLTableRowElement::deleteCell(int index, ExceptionCode& ec)
 
 PassRefPtr<HTMLCollection> HTMLTableRowElement::cells()
 {
-    return HTMLCollection::create(this, TRCells);
+    return ensureCachedHTMLCollection(TRCells);
 }
 
 void HTMLTableRowElement::setCells(HTMLCollection*, ExceptionCode& ec)
index 74343b5..6a8567c 100644 (file)
@@ -152,7 +152,7 @@ HTMLTableRowElement* HTMLTableRowsCollection::lastRow(HTMLTableElement* table)
 // table to get at the collection cache. Order of argument evaluation is undefined and can
 // differ between compilers.
 HTMLTableRowsCollection::HTMLTableRowsCollection(HTMLTableElement* table)
-    : HTMLCollection(table, OtherCollection, /* retainBaseNode */ false)
+    : HTMLCollection(table, OtherCollection)
 {
 }
 
index 5ef25f1..73a8367 100644 (file)
@@ -151,7 +151,7 @@ void HTMLTableSectionElement::setVAlign(const String &value)
 
 PassRefPtr<HTMLCollection> HTMLTableSectionElement::rows()
 {
-    return HTMLCollection::create(this, TSectionRows);
+    return ensureCachedHTMLCollection(TSectionRows);
 }
 
 }