- Revision
- 99869
- Author
- [email protected]
- Date
- 2011-11-10 09:09:19 -0800 (Thu, 10 Nov 2011)
Log Message
Cache and reuse HTMLCollections exposed by Document.
<http://webkit.org/b/71956>
Reviewed by Antti Koivisto.
Source/WebCore:
Let Document cache the various HTMLCollection objects it exposes.
They're created on-demand and stored in a tight Vector.
This is a behavior change, since the lifetime of returned collections
is now tied to the lifetime of the Document. However, this matches the
current behavior of Firefox and Opera.
This reduces memory consumption by ~800 kB (on 64-bit) when loading
the full HTML5 spec. document.links was called 34001 times, yielding
34001 separate HTMLCollections, and now we only need 1.
The document.all collection retains the old behavior, as caching it
would be a bit more complicated.
* dom/Document.cpp:
(WebCore::Document::Document):
(WebCore::Document::collection):
(WebCore::Document::images):
(WebCore::Document::applets):
(WebCore::Document::embeds):
(WebCore::Document::plugins):
(WebCore::Document::objects):
(WebCore::Document::scripts):
(WebCore::Document::links):
(WebCore::Document::forms):
(WebCore::Document::anchors):
* dom/Document.h:
* html/CollectionType.h:
LayoutTests:
Update fast/dom/gc-9.html to document the new lifetime behavior of
HTMLCollection objects returned by document.
* fast/dom/gc-9-expected.txt:
* fast/dom/gc-9.html:
Modified Paths
Diff
Modified: trunk/LayoutTests/ChangeLog (99868 => 99869)
--- trunk/LayoutTests/ChangeLog 2011-11-10 17:07:17 UTC (rev 99868)
+++ trunk/LayoutTests/ChangeLog 2011-11-10 17:09:19 UTC (rev 99869)
@@ -1,3 +1,16 @@
+2011-11-10 Andreas Kling <[email protected]>
+
+ Cache and reuse HTMLCollections exposed by Document.
+ <http://webkit.org/b/71956>
+
+ Reviewed by Antti Koivisto.
+
+ Update fast/dom/gc-9.html to document the new lifetime behavior of
+ HTMLCollection objects returned by document.
+
+ * fast/dom/gc-9-expected.txt:
+ * fast/dom/gc-9.html:
+
2011-11-10 Tony Gentilcore <[email protected]>
Chromium layout test rebaseline.
Modified: trunk/LayoutTests/fast/dom/gc-9-expected.txt (99868 => 99869)
--- trunk/LayoutTests/fast/dom/gc-9-expected.txt 2011-11-10 17:07:17 UTC (rev 99868)
+++ trunk/LayoutTests/fast/dom/gc-9-expected.txt 2011-11-10 17:09:19 UTC (rev 99869)
@@ -16,13 +16,13 @@
PASS: document.getElementsByTagName('select')[0].options.myCustomProperty should be undefined and is.
PASS: document.all.myCustomProperty should be undefined and is.
PASS: document.body.childNodes.myCustomProperty should be undefined and is.
-PASS: document.images.myCustomProperty should be undefined and is.
-PASS: document.embeds.myCustomProperty should be undefined and is.
-PASS: document.applets.myCustomProperty should be undefined and is.
-PASS: document.links.myCustomProperty should be undefined and is.
-PASS: document.forms.myCustomProperty should be undefined and is.
-PASS: document.anchors.myCustomProperty should be undefined and is.
-PASS: document.scripts.myCustomProperty should be undefined and is.
+PASS: document.images.myCustomProperty should be 1 and is.
+PASS: document.embeds.myCustomProperty should be 1 and is.
+PASS: document.applets.myCustomProperty should be 1 and is.
+PASS: document.links.myCustomProperty should be 1 and is.
+PASS: document.forms.myCustomProperty should be 1 and is.
+PASS: document.anchors.myCustomProperty should be 1 and is.
+PASS: document.scripts.myCustomProperty should be 1 and is.
PASS: document.getElementsByTagName('form')[0].elements.myCustomProperty should be undefined and is.
PASS: document.getElementsByTagName('table')[0].rows.myCustomProperty should be undefined and is.
PASS: document.getElementsByTagName('table')[0].rows[0].cells.myCustomProperty should be undefined and is.
@@ -52,13 +52,13 @@
PASS: document.getElementsByTagName('select')[0].options.myCustomProperty should be undefined and is.
PASS: document.all.myCustomProperty should be undefined and is.
PASS: document.body.childNodes.myCustomProperty should be undefined and is.
-PASS: document.images.myCustomProperty should be undefined and is.
-PASS: document.embeds.myCustomProperty should be undefined and is.
-PASS: document.applets.myCustomProperty should be undefined and is.
-PASS: document.links.myCustomProperty should be undefined and is.
-PASS: document.forms.myCustomProperty should be undefined and is.
-PASS: document.anchors.myCustomProperty should be undefined and is.
-PASS: document.scripts.myCustomProperty should be undefined and is.
+PASS: document.images.myCustomProperty should be 1 and is.
+PASS: document.embeds.myCustomProperty should be 1 and is.
+PASS: document.applets.myCustomProperty should be 1 and is.
+PASS: document.links.myCustomProperty should be 1 and is.
+PASS: document.forms.myCustomProperty should be 1 and is.
+PASS: document.anchors.myCustomProperty should be 1 and is.
+PASS: document.scripts.myCustomProperty should be 1 and is.
PASS: document.getElementsByTagName('form')[0].elements.myCustomProperty should be undefined and is.
PASS: document.getElementsByTagName('table')[0].rows.myCustomProperty should be undefined and is.
PASS: document.getElementsByTagName('table')[0].rows[0].cells.myCustomProperty should be undefined and is.
Modified: trunk/LayoutTests/fast/dom/gc-9.html (99868 => 99869)
--- trunk/LayoutTests/fast/dom/gc-9.html 2011-11-10 17:07:17 UTC (rev 99868)
+++ trunk/LayoutTests/fast/dom/gc-9.html 2011-11-10 17:09:19 UTC (rev 99869)
@@ -126,13 +126,13 @@
[ "document.all" ],
[ "document.body.childNodes" ],
- [ "document.images" ],
- [ "document.embeds" ],
- [ "document.applets" ],
- [ "document.links" ],
- [ "document.forms" ],
- [ "document.anchors" ],
- [ "document.scripts" ],
+ [ "document.images", "allow custom" ],
+ [ "document.embeds", "allow custom" ],
+ [ "document.applets", "allow custom" ],
+ [ "document.links", "allow custom" ],
+ [ "document.forms", "allow custom" ],
+ [ "document.anchors", "allow custom" ],
+ [ "document.scripts", "allow custom" ],
[ "document.getElementsByTagName('form')[0].elements" ],
[ "document.getElementsByTagName('table')[0].rows" ],
Modified: trunk/Source/WebCore/ChangeLog (99868 => 99869)
--- trunk/Source/WebCore/ChangeLog 2011-11-10 17:07:17 UTC (rev 99868)
+++ trunk/Source/WebCore/ChangeLog 2011-11-10 17:09:19 UTC (rev 99869)
@@ -1,3 +1,38 @@
+2011-11-10 Andreas Kling <[email protected]>
+
+ Cache and reuse HTMLCollections exposed by Document.
+ <http://webkit.org/b/71956>
+
+ Reviewed by Antti Koivisto.
+
+ Let Document cache the various HTMLCollection objects it exposes.
+ They're created on-demand and stored in a tight Vector.
+ This is a behavior change, since the lifetime of returned collections
+ is now tied to the lifetime of the Document. However, this matches the
+ current behavior of Firefox and Opera.
+
+ This reduces memory consumption by ~800 kB (on 64-bit) when loading
+ the full HTML5 spec. document.links was called 34001 times, yielding
+ 34001 separate HTMLCollections, and now we only need 1.
+
+ The document.all collection retains the old behavior, as caching it
+ would be a bit more complicated.
+
+ * dom/Document.cpp:
+ (WebCore::Document::Document):
+ (WebCore::Document::collection):
+ (WebCore::Document::images):
+ (WebCore::Document::applets):
+ (WebCore::Document::embeds):
+ (WebCore::Document::plugins):
+ (WebCore::Document::objects):
+ (WebCore::Document::scripts):
+ (WebCore::Document::links):
+ (WebCore::Document::forms):
+ (WebCore::Document::anchors):
+ * dom/Document.h:
+ * html/CollectionType.h:
+
2011-11-10 Alexander Pavlov <[email protected]>
Web Inspector: [SuggestBox] Correctly position the box under the first character of the suggestion prefix.
Modified: trunk/Source/WebCore/dom/Document.cpp (99868 => 99869)
--- trunk/Source/WebCore/dom/Document.cpp 2011-11-10 17:07:17 UTC (rev 99868)
+++ trunk/Source/WebCore/dom/Document.cpp 2011-11-10 17:09:19 UTC (rev 99869)
@@ -411,7 +411,7 @@
, m_writeRecursionIsTooDeep(false)
, m_writeRecursionDepth(0)
, m_wheelEventHandlerCount(0)
-{
+{
m_document = this;
m_pageGroupUserSheetCacheValid = false;
@@ -4096,50 +4096,59 @@
}
#endif
+const RefPtr<HTMLCollection>& Document::collection(CollectionType type)
+{
+ ASSERT(type < NumCollectionTypes);
+ if (!m_collections[type])
+ m_collections[type] = HTMLCollection::create(this, type);
+ ASSERT(m_collections[type]);
+ return m_collections[type];
+}
+
PassRefPtr<HTMLCollection> Document::images()
{
- return HTMLCollection::create(this, DocImages);
+ return collection(DocImages);
}
PassRefPtr<HTMLCollection> Document::applets()
{
- return HTMLCollection::create(this, DocApplets);
+ return collection(DocApplets);
}
PassRefPtr<HTMLCollection> Document::embeds()
{
- return HTMLCollection::create(this, DocEmbeds);
+ return collection(DocEmbeds);
}
PassRefPtr<HTMLCollection> Document::plugins()
{
// This is an alias for embeds() required for the JS DOM bindings.
- return HTMLCollection::create(this, DocEmbeds);
+ return collection(DocEmbeds);
}
PassRefPtr<HTMLCollection> Document::objects()
{
- return HTMLCollection::create(this, DocObjects);
+ return collection(DocObjects);
}
PassRefPtr<HTMLCollection> Document::scripts()
{
- return HTMLCollection::create(this, DocScripts);
+ return collection(DocScripts);
}
PassRefPtr<HTMLCollection> Document::links()
{
- return HTMLCollection::create(this, DocLinks);
+ return collection(DocLinks);
}
PassRefPtr<HTMLCollection> Document::forms()
{
- return HTMLCollection::create(this, DocForms);
+ return collection(DocForms);
}
PassRefPtr<HTMLCollection> Document::anchors()
{
- return HTMLCollection::create(this, DocAnchors);
+ return collection(DocAnchors);
}
PassRefPtr<HTMLAllCollection> Document::all()
Modified: trunk/Source/WebCore/dom/Document.h (99868 => 99869)
--- trunk/Source/WebCore/dom/Document.h 2011-11-10 17:07:17 UTC (rev 99868)
+++ trunk/Source/WebCore/dom/Document.h 2011-11-10 17:09:19 UTC (rev 99869)
@@ -1424,6 +1424,9 @@
#if ENABLE(REQUEST_ANIMATION_FRAME)
OwnPtr<ScriptedAnimationController> m_scriptedAnimationController;
#endif
+
+ const RefPtr<HTMLCollection>& collection(CollectionType);
+ RefPtr<HTMLCollection> m_collections[NumCollectionTypes];
};
// Put these methods here, because they require the Document definition, but we really want to inline them.
Modified: trunk/Source/WebCore/html/CollectionType.h (99868 => 99869)
--- trunk/Source/WebCore/html/CollectionType.h 2011-11-10 17:07:17 UTC (rev 99868)
+++ trunk/Source/WebCore/html/CollectionType.h 2011-11-10 17:09:19 UTC (rev 99869)
@@ -54,7 +54,9 @@
DataListOptions,
MapAreas,
- OtherCollection
+ OtherCollection,
+
+ NumCollectionTypes
};
static const CollectionType FirstUnnamedDocumentCachedType = DocImages;