Title: [103883] trunk
Revision
103883
Author
kl...@webkit.org
Date
2012-01-01 13:05:42 -0800 (Sun, 01 Jan 2012)

Log Message

Move the remaining collections to caching on their respective base nodes.
<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.

Modified Paths

Added Paths

Removed Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (103882 => 103883)


--- trunk/LayoutTests/ChangeLog	2012-01-01 20:56:27 UTC (rev 103882)
+++ trunk/LayoutTests/ChangeLog	2012-01-01 21:05:42 UTC (rev 103883)
@@ -1,3 +1,27 @@
+2012-01-01  Andreas Kling  <awesomekl...@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  <kbal...@webkit.org>
 
         [Qt] Layout divergence between WK1/2 in table tests

Added: trunk/LayoutTests/fast/dom/collection-idempotence-expected.txt (0 => 103883)


--- trunk/LayoutTests/fast/dom/collection-idempotence-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/collection-idempotence-expected.txt	2012-01-01 21:05:42 UTC (rev 103883)
@@ -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
+ 

Added: trunk/LayoutTests/fast/dom/collection-idempotence.html (0 => 103883)


--- trunk/LayoutTests/fast/dom/collection-idempotence.html	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/collection-idempotence.html	2012-01-01 21:05:42 UTC (rev 103883)
@@ -0,0 +1,40 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="utf-8">
+<script src=""
+</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=""
+</body>
+</html>

Deleted: trunk/LayoutTests/fast/dom/document-collection-idempotence-expected.txt (103882 => 103883)


--- trunk/LayoutTests/fast/dom/document-collection-idempotence-expected.txt	2012-01-01 20:56:27 UTC (rev 103882)
+++ trunk/LayoutTests/fast/dom/document-collection-idempotence-expected.txt	2012-01-01 21:05:42 UTC (rev 103883)
@@ -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
-

Deleted: trunk/LayoutTests/fast/dom/document-collection-idempotence.html (103882 => 103883)


--- trunk/LayoutTests/fast/dom/document-collection-idempotence.html	2012-01-01 20:56:27 UTC (rev 103882)
+++ trunk/LayoutTests/fast/dom/document-collection-idempotence.html	2012-01-01 21:05:42 UTC (rev 103883)
@@ -1,22 +0,0 @@
-<!DOCTYPE html>
-<html>
-<head>
-<meta charset="utf-8">
-<script src=""
-</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=""
-</body>
-</html>

Deleted: trunk/LayoutTests/fast/dom/form-elements-collection-idempotence-expected.txt (103882 => 103883)


--- trunk/LayoutTests/fast/dom/form-elements-collection-idempotence-expected.txt	2012-01-01 20:56:27 UTC (rev 103882)
+++ trunk/LayoutTests/fast/dom/form-elements-collection-idempotence-expected.txt	2012-01-01 21:05:42 UTC (rev 103883)
@@ -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
-

Deleted: trunk/LayoutTests/fast/dom/form-elements-collection-idempotence.html (103882 => 103883)


--- trunk/LayoutTests/fast/dom/form-elements-collection-idempotence.html	2012-01-01 20:56:27 UTC (rev 103882)
+++ trunk/LayoutTests/fast/dom/form-elements-collection-idempotence.html	2012-01-01 21:05:42 UTC (rev 103883)
@@ -1,20 +0,0 @@
-<!DOCTYPE html>
-<html>
-<head>
-<meta charset="utf-8">
-<script src=""
-</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=""
-</body>
-</html>

Deleted: trunk/LayoutTests/fast/dom/select-options-collection-idempotence-expected.txt (103882 => 103883)


--- trunk/LayoutTests/fast/dom/select-options-collection-idempotence-expected.txt	2012-01-01 20:56:27 UTC (rev 103882)
+++ trunk/LayoutTests/fast/dom/select-options-collection-idempotence-expected.txt	2012-01-01 21:05:42 UTC (rev 103883)
@@ -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
-

Deleted: trunk/LayoutTests/fast/dom/select-options-collection-idempotence.html (103882 => 103883)


--- trunk/LayoutTests/fast/dom/select-options-collection-idempotence.html	2012-01-01 20:56:27 UTC (rev 103882)
+++ trunk/LayoutTests/fast/dom/select-options-collection-idempotence.html	2012-01-01 21:05:42 UTC (rev 103883)
@@ -1,20 +0,0 @@
-<!DOCTYPE html>
-<html>
-<head>
-<meta charset="utf-8">
-<script src=""
-</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=""
-</body>
-</html>

Deleted: trunk/LayoutTests/fast/dom/table-rows-collection-idempotence-expected.txt (103882 => 103883)


--- trunk/LayoutTests/fast/dom/table-rows-collection-idempotence-expected.txt	2012-01-01 20:56:27 UTC (rev 103882)
+++ trunk/LayoutTests/fast/dom/table-rows-collection-idempotence-expected.txt	2012-01-01 21:05:42 UTC (rev 103883)
@@ -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
-

Deleted: trunk/LayoutTests/fast/dom/table-rows-collection-idempotence.html (103882 => 103883)


--- trunk/LayoutTests/fast/dom/table-rows-collection-idempotence.html	2012-01-01 20:56:27 UTC (rev 103882)
+++ trunk/LayoutTests/fast/dom/table-rows-collection-idempotence.html	2012-01-01 21:05:42 UTC (rev 103883)
@@ -1,20 +0,0 @@
-<!DOCTYPE html>
-<html>
-<head>
-<meta charset="utf-8">
-<script src=""
-</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=""
-</body>
-</html>

Modified: trunk/Source/WebCore/ChangeLog (103882 => 103883)


--- trunk/Source/WebCore/ChangeLog	2012-01-01 20:56:27 UTC (rev 103882)
+++ trunk/Source/WebCore/ChangeLog	2012-01-01 21:05:42 UTC (rev 103883)
@@ -1,3 +1,64 @@
+2012-01-01  Andreas Kling  <awesomekl...@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....@intel.com>
 
         Use overload methods to implement [Optional] parameters in AudioNode.idl

Modified: trunk/Source/WebCore/dom/Document.cpp (103882 => 103883)


--- trunk/Source/WebCore/dom/Document.cpp	2012-01-01 20:56:27 UTC (rev 103882)
+++ trunk/Source/WebCore/dom/Document.cpp	2012-01-01 21:05:42 UTC (rev 103883)
@@ -4203,7 +4203,7 @@
 {
     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];
 }
 

Modified: trunk/Source/WebCore/dom/Element.cpp (103882 => 103883)


--- trunk/Source/WebCore/dom/Element.cpp	2012-01-01 20:56:27 UTC (rev 103882)
+++ trunk/Source/WebCore/dom/Element.cpp	2012-01-01 21:05:42 UTC (rev 103883)
@@ -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 @@
     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 @@
         static_cast<HTMLDocument*>(document())->addExtraNamedItem(newId);
 }
 
+HTMLCollection* Element::ensureCachedHTMLCollection(CollectionType type)
+{
+    return ensureRareData()->ensureCachedHTMLCollection(this, type);
+}
+
 } // namespace WebCore

Modified: trunk/Source/WebCore/dom/Element.h (103882 => 103883)


--- trunk/Source/WebCore/dom/Element.h	2012-01-01 20:56:27 UTC (rev 103882)
+++ trunk/Source/WebCore/dom/Element.h	2012-01-01 21:05:42 UTC (rev 103883)
@@ -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 @@
     
     void idAttributeChanged(Attribute*);
 
+    HTMLCollection* ensureCachedHTMLCollection(CollectionType);
+
 private:
     void scrollByUnits(int units, ScrollGranularity);
 

Modified: trunk/Source/WebCore/dom/ElementRareData.h (103882 => 103883)


--- trunk/Source/WebCore/dom/ElementRareData.h	2012-01-01 20:56:27 UTC (rev 103882)
+++ trunk/Source/WebCore/dom/ElementRareData.h	2012-01-01 21:05:42 UTC (rev 103883)
@@ -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 @@
     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;

Modified: trunk/Source/WebCore/html/CollectionType.h (103882 => 103883)


--- trunk/Source/WebCore/html/CollectionType.h	2012-01-01 20:56:27 UTC (rev 103882)
+++ trunk/Source/WebCore/html/CollectionType.h	2012-01-01 21:05:42 UTC (rev 103883)
@@ -38,7 +38,6 @@
     DocScripts,   // all <script> elements
 
     DocAll,       // "all" elements (IE)
-    NodeChildren, // first-level children (IE)
 
     // named collection types cached in the document
 
@@ -47,6 +46,7 @@
 
     // 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,8 +62,11 @@
 };
 
 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
 
 #endif

Modified: trunk/Source/WebCore/html/HTMLCollection.cpp (103882 => 103883)


--- trunk/Source/WebCore/html/HTMLCollection.cpp	2012-01-01 20:56:27 UTC (rev 103882)
+++ trunk/Source/WebCore/html/HTMLCollection.cpp	2012-01-01 21:05:42 UTC (rev 103883)
@@ -37,26 +37,13 @@
 
 using namespace HTMLNames;
 
-HTMLCollection::HTMLCollection(Document* document, CollectionType type)
-    : m_baseIsRetained(false)
-    , m_includeChildren(shouldIncludeChildren(type))
+HTMLCollection::HTMLCollection(Node* base, CollectionType type)
+    : 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))
-    , 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 @@
     return false;
 }
 
-PassRefPtr<HTMLCollection> HTMLCollection::createForCachingOnDocument(Document* document, CollectionType type)
+PassRefPtr<HTMLCollection> HTMLCollection::create(Node* base, CollectionType type)
 {
-    return adoptRef(new HTMLCollection(document, type));
+    return adoptRef(new HTMLCollection(base, type));
 }
 
-PassRefPtr<HTMLCollection> HTMLCollection::create(PassRefPtr<Node> base, CollectionType type)
-{
-    return adoptRef(new HTMLCollection(base.get(), 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

Modified: trunk/Source/WebCore/html/HTMLCollection.h (103882 => 103883)


--- trunk/Source/WebCore/html/HTMLCollection.h	2012-01-01 20:56:27 UTC (rev 103882)
+++ trunk/Source/WebCore/html/HTMLCollection.h	2012-01-01 21:05:42 UTC (rev 103883)
@@ -40,10 +40,9 @@
 
 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 @@
     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 @@
 
     bool isAcceptableElement(Element*) const;
 
-    bool m_baseIsRetained : 1;
     bool m_includeChildren : 1;
     mutable bool m_ownsInfo : 1;
     unsigned m_type : 5; // CollectionType

Modified: trunk/Source/WebCore/html/HTMLDataListElement.cpp (103882 => 103883)


--- trunk/Source/WebCore/html/HTMLDataListElement.cpp	2012-01-01 20:56:27 UTC (rev 103882)
+++ trunk/Source/WebCore/html/HTMLDataListElement.cpp	2012-01-01 21:05:42 UTC (rev 103883)
@@ -49,7 +49,7 @@
 
 PassRefPtr<HTMLCollection> HTMLDataListElement::options()
 {
-    return HTMLCollection::create(this, DataListOptions);
+    return ensureCachedHTMLCollection(DataListOptions);
 }
 
 }  // namespace WebCore

Modified: trunk/Source/WebCore/html/HTMLElement.cpp (103882 => 103883)


--- trunk/Source/WebCore/html/HTMLElement.cpp	2012-01-01 20:56:27 UTC (rev 103882)
+++ trunk/Source/WebCore/html/HTMLElement.cpp	2012-01-01 21:05:42 UTC (rev 103883)
@@ -827,7 +827,7 @@
 
 PassRefPtr<HTMLCollection> HTMLElement::children()
 {
-    return HTMLCollection::create(this, NodeChildren);
+    return ensureCachedHTMLCollection(NodeChildren);
 }
 
 bool HTMLElement::rendererIsNeeded(const NodeRenderingContext& context)

Modified: trunk/Source/WebCore/html/HTMLFormCollection.cpp (103882 => 103883)


--- trunk/Source/WebCore/html/HTMLFormCollection.cpp	2012-01-01 20:56:27 UTC (rev 103882)
+++ trunk/Source/WebCore/html/HTMLFormCollection.cpp	2012-01-01 21:05:42 UTC (rev 103883)
@@ -37,7 +37,7 @@
 // calculation every time if anything has changed.
 
 HTMLFormCollection::HTMLFormCollection(HTMLFormElement* form)
-    : HTMLCollection(form, OtherCollection, /* retainBaseNode */ false)
+    : HTMLCollection(form, OtherCollection)
 {
 }
 

Modified: trunk/Source/WebCore/html/HTMLMapElement.cpp (103882 => 103883)


--- trunk/Source/WebCore/html/HTMLMapElement.cpp	2012-01-01 20:56:27 UTC (rev 103882)
+++ trunk/Source/WebCore/html/HTMLMapElement.cpp	2012-01-01 21:05:42 UTC (rev 103883)
@@ -128,7 +128,7 @@
 
 PassRefPtr<HTMLCollection> HTMLMapElement::areas()
 {
-    return HTMLCollection::create(this, MapAreas);
+    return ensureCachedHTMLCollection(MapAreas);
 }
 
 void HTMLMapElement::insertedIntoDocument()

Modified: trunk/Source/WebCore/html/HTMLNameCollection.cpp (103882 => 103883)


--- trunk/Source/WebCore/html/HTMLNameCollection.cpp	2012-01-01 20:56:27 UTC (rev 103882)
+++ trunk/Source/WebCore/html/HTMLNameCollection.cpp	2012-01-01 21:05:42 UTC (rev 103883)
@@ -33,7 +33,7 @@
 using namespace HTMLNames;
 
 HTMLNameCollection::HTMLNameCollection(Document* document, CollectionType type, const AtomicString& name)
-    : HTMLCollection(document, type, /* retainBaseNode */ false)
+    : HTMLCollection(document, type)
     , m_name(name)
 {
 }

Modified: trunk/Source/WebCore/html/HTMLOptionsCollection.cpp (103882 => 103883)


--- trunk/Source/WebCore/html/HTMLOptionsCollection.cpp	2012-01-01 20:56:27 UTC (rev 103882)
+++ trunk/Source/WebCore/html/HTMLOptionsCollection.cpp	2012-01-01 21:05:42 UTC (rev 103883)
@@ -29,7 +29,7 @@
 namespace WebCore {
 
 HTMLOptionsCollection::HTMLOptionsCollection(HTMLSelectElement* select)
-    : HTMLCollection(select, SelectOptions, /* retainBaseNode */ false)
+    : HTMLCollection(select, SelectOptions)
 {
 }
 

Modified: trunk/Source/WebCore/html/HTMLTableElement.cpp (103882 => 103883)


--- trunk/Source/WebCore/html/HTMLTableElement.cpp	2012-01-01 20:56:27 UTC (rev 103882)
+++ trunk/Source/WebCore/html/HTMLTableElement.cpp	2012-01-01 21:05:42 UTC (rev 103883)
@@ -633,7 +633,7 @@
 
 PassRefPtr<HTMLCollection> HTMLTableElement::tBodies()
 {
-    return HTMLCollection::create(this, TableTBodies);
+    return ensureCachedHTMLCollection(TableTBodies);
 }
 
 String HTMLTableElement::rules() const

Modified: trunk/Source/WebCore/html/HTMLTableRowElement.cpp (103882 => 103883)


--- trunk/Source/WebCore/html/HTMLTableRowElement.cpp	2012-01-01 20:56:27 UTC (rev 103882)
+++ trunk/Source/WebCore/html/HTMLTableRowElement.cpp	2012-01-01 21:05:42 UTC (rev 103883)
@@ -156,7 +156,7 @@
 
 PassRefPtr<HTMLCollection> HTMLTableRowElement::cells()
 {
-    return HTMLCollection::create(this, TRCells);
+    return ensureCachedHTMLCollection(TRCells);
 }
 
 void HTMLTableRowElement::setCells(HTMLCollection*, ExceptionCode& ec)

Modified: trunk/Source/WebCore/html/HTMLTableRowsCollection.cpp (103882 => 103883)


--- trunk/Source/WebCore/html/HTMLTableRowsCollection.cpp	2012-01-01 20:56:27 UTC (rev 103882)
+++ trunk/Source/WebCore/html/HTMLTableRowsCollection.cpp	2012-01-01 21:05:42 UTC (rev 103883)
@@ -152,7 +152,7 @@
 // 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)
 {
 }
 

Modified: trunk/Source/WebCore/html/HTMLTableSectionElement.cpp (103882 => 103883)


--- trunk/Source/WebCore/html/HTMLTableSectionElement.cpp	2012-01-01 20:56:27 UTC (rev 103882)
+++ trunk/Source/WebCore/html/HTMLTableSectionElement.cpp	2012-01-01 21:05:42 UTC (rev 103883)
@@ -151,7 +151,7 @@
 
 PassRefPtr<HTMLCollection> HTMLTableSectionElement::rows()
 {
-    return HTMLCollection::create(this, TSectionRows);
+    return ensureCachedHTMLCollection(TSectionRows);
 }
 
 }
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to