Diff
Modified: trunk/Source/WebCore/ChangeLog (103864 => 103865)
--- trunk/Source/WebCore/ChangeLog 2012-01-01 00:50:00 UTC (rev 103864)
+++ trunk/Source/WebCore/ChangeLog 2012-01-01 00:56:01 UTC (rev 103865)
@@ -1,5 +1,45 @@
2012-01-01 Andreas Kling <[email protected]>
+ Cache named item collections on Document, not just their caches.
+ <http://webkit.org/b/75403>
+
+ Reviewed by Anders Carlsson.
+
+ Keep two maps of name -> RefPtr<HTMLNameCollection> on Document. We already
+ had maps for the CollectionCaches and were creating the HTMLNameCollections
+ every time they were accessed. We now let the collections create and manage
+ the CollectionCaches instead of Document.
+
+ No new tests since these collections are not exposed to the web.
+
+ * dom/Document.h:
+ * dom/Document.cpp:
+ (WebCore::Document::windowNamedItems):
+ (WebCore::Document::documentNamedItems):
+
+ Replace the name/CollectionCache maps by name/HTMLNameCollection maps.
+
+ * bindings/js/JSDOMWindowCustom.cpp:
+ (WebCore::namedItemGetter):
+ * bindings/js/JSHTMLDocumentCustom.cpp:
+ (WebCore::JSHTMLDocument::nameGetter):
+
+ Pass names as AtomicStrings to Document's collection getters.
+
+ * html/HTMLNameCollection.h:
+ (WebCore::HTMLNameCollection::create):
+ * html/HTMLNameCollection.cpp:
+ (WebCore::HTMLNameCollection::HTMLNameCollection):
+
+ Store the name in an AtomicString instead of a String, incidentally
+ making traversal of HTMLNameCollections more efficient.
+
+ * html/CollectionType.h:
+
+ Remove two now-unneeded constants.
+
+2012-01-01 Andreas Kling <[email protected]>
+
Remove Document::collectionInfo() and let collections manage their caches.
<http://webkit.org/b/75401>
Modified: trunk/Source/WebCore/bindings/js/JSDOMWindowCustom.cpp (103864 => 103865)
--- trunk/Source/WebCore/bindings/js/JSDOMWindowCustom.cpp 2012-01-01 00:50:00 UTC (rev 103864)
+++ trunk/Source/WebCore/bindings/js/JSDOMWindowCustom.cpp 2012-01-01 00:56:01 UTC (rev 103865)
@@ -115,7 +115,7 @@
ASSERT(document);
ASSERT(document->isHTMLDocument());
- RefPtr<HTMLCollection> collection = document->windowNamedItems(identifierToString(propertyName));
+ RefPtr<HTMLCollection> collection = document->windowNamedItems(identifierToAtomicString(propertyName));
if (collection->length() == 1)
return toJS(exec, thisObj, collection->firstItem());
return toJS(exec, thisObj, collection.get());
Modified: trunk/Source/WebCore/bindings/js/JSHTMLDocumentCustom.cpp (103864 => 103865)
--- trunk/Source/WebCore/bindings/js/JSHTMLDocumentCustom.cpp 2012-01-01 00:50:00 UTC (rev 103864)
+++ trunk/Source/WebCore/bindings/js/JSHTMLDocumentCustom.cpp 2012-01-01 00:56:01 UTC (rev 103865)
@@ -61,8 +61,7 @@
JSHTMLDocument* thisObj = static_cast<JSHTMLDocument*>(asObject(slotBase));
HTMLDocument* document = static_cast<HTMLDocument*>(thisObj->impl());
- String name = identifierToString(propertyName);
- RefPtr<HTMLCollection> collection = document->documentNamedItems(name);
+ RefPtr<HTMLCollection> collection = document->documentNamedItems(identifierToAtomicString(propertyName));
unsigned length = collection->length();
if (!length)
Modified: trunk/Source/WebCore/dom/Document.cpp (103864 => 103865)
--- trunk/Source/WebCore/dom/Document.cpp 2012-01-01 00:50:00 UTC (rev 103864)
+++ trunk/Source/WebCore/dom/Document.cpp 2012-01-01 00:56:01 UTC (rev 103865)
@@ -41,7 +41,6 @@
#include "CachedResourceLoader.h"
#include "Chrome.h"
#include "ChromeClient.h"
-#include "CollectionCache.h"
#include "Comment.h"
#include "Console.h"
#include "ContentSecurityPolicy.h"
@@ -4253,29 +4252,22 @@
return m_allCollection;
}
-PassRefPtr<HTMLCollection> Document::windowNamedItems(const String &name)
+PassRefPtr<HTMLCollection> Document::windowNamedItems(const AtomicString& name)
{
- return HTMLNameCollection::create(this, WindowNamedItems, name);
+ RefPtr<HTMLNameCollection>& collection = m_windowNamedItemCollections.add(name.impl(), 0).first->second;
+ if (!collection)
+ collection = HTMLNameCollection::create(this, WindowNamedItems, name);
+ return collection;
}
-PassRefPtr<HTMLCollection> Document::documentNamedItems(const String &name)
+PassRefPtr<HTMLCollection> Document::documentNamedItems(const AtomicString& name)
{
- return HTMLNameCollection::create(this, DocumentNamedItems, name);
+ RefPtr<HTMLNameCollection>& collection = m_documentNamedItemCollections.add(name.impl(), 0).first->second;
+ if (!collection)
+ collection = HTMLNameCollection::create(this, DocumentNamedItems, name);
+ return collection;
}
-CollectionCache* Document::nameCollectionInfo(CollectionType type, const AtomicString& name)
-{
- ASSERT(type >= FirstNamedDocumentCachedType);
- unsigned index = type - FirstNamedDocumentCachedType;
- ASSERT(index < NumNamedDocumentCachedTypes);
-
- OwnPtr<CollectionCache>& cache = m_nameCollectionInfo[index].add(name.impl(), nullptr).first->second;
- if (!cache)
- cache = adoptPtr(new CollectionCache);
- cache->checkConsistency();
- return cache.get();
-}
-
void Document::finishedParsing()
{
ASSERT(!scriptableDocumentParser() || !m_parser->isParsing());
Modified: trunk/Source/WebCore/dom/Document.h (103864 => 103865)
--- trunk/Source/WebCore/dom/Document.h 2012-01-01 00:50:00 UTC (rev 103864)
+++ trunk/Source/WebCore/dom/Document.h 2012-01-01 00:56:01 UTC (rev 103865)
@@ -98,6 +98,7 @@
class HTMLHeadElement;
class HTMLInputElement;
class HTMLMapElement;
+class HTMLNameCollection;
class HitTestRequest;
class HitTestResult;
class IntPoint;
@@ -137,8 +138,6 @@
class XPathNSResolver;
class XPathResult;
-struct CollectionCache;
-
#if ENABLE(SVG)
class SVGDocumentExtensions;
#endif
@@ -420,13 +419,11 @@
PassRefPtr<HTMLCollection> anchors();
PassRefPtr<HTMLCollection> objects();
PassRefPtr<HTMLCollection> scripts();
- PassRefPtr<HTMLCollection> windowNamedItems(const String& name);
- PassRefPtr<HTMLCollection> documentNamedItems(const String& name);
+ PassRefPtr<HTMLCollection> windowNamedItems(const AtomicString& name);
+ PassRefPtr<HTMLCollection> documentNamedItems(const AtomicString& name);
PassRefPtr<HTMLAllCollection> all();
- CollectionCache* nameCollectionInfo(CollectionType, const AtomicString& name);
-
// Other methods (not part of DOM)
bool isHTMLDocument() const { return m_isHTML; }
bool isXHTMLDocument() const { return m_isXHTML; }
@@ -1364,8 +1361,9 @@
RefPtr<HTMLCollection> m_collections[NumUnnamedDocumentCachedTypes];
RefPtr<HTMLAllCollection> m_allCollection;
- typedef HashMap<AtomicStringImpl*, OwnPtr<CollectionCache> > NamedCollectionMap;
- FixedArray<NamedCollectionMap, NumNamedDocumentCachedTypes> m_nameCollectionInfo;
+ typedef HashMap<AtomicStringImpl*, RefPtr<HTMLNameCollection> > NamedCollectionMap;
+ NamedCollectionMap m_documentNamedItemCollections;
+ NamedCollectionMap m_windowNamedItemCollections;
RefPtr<XPathEvaluator> m_xpathEvaluator;
Modified: trunk/Source/WebCore/html/CollectionType.h (103864 => 103865)
--- trunk/Source/WebCore/html/CollectionType.h 2012-01-01 00:50:00 UTC (rev 103864)
+++ trunk/Source/WebCore/html/CollectionType.h 2012-01-01 00:56:01 UTC (rev 103865)
@@ -64,9 +64,6 @@
static const CollectionType FirstUnnamedDocumentCachedType = DocImages;
static const unsigned NumUnnamedDocumentCachedTypes = NodeChildren - DocImages + 1;
-static const CollectionType FirstNamedDocumentCachedType = WindowNamedItems;
-static const unsigned NumNamedDocumentCachedTypes = DocumentNamedItems - WindowNamedItems + 1;
-
} // namespace
#endif
Modified: trunk/Source/WebCore/html/HTMLNameCollection.cpp (103864 => 103865)
--- trunk/Source/WebCore/html/HTMLNameCollection.cpp 2012-01-01 00:50:00 UTC (rev 103864)
+++ trunk/Source/WebCore/html/HTMLNameCollection.cpp 2012-01-01 00:56:01 UTC (rev 103865)
@@ -32,8 +32,8 @@
using namespace HTMLNames;
-HTMLNameCollection::HTMLNameCollection(PassRefPtr<Document> document, CollectionType type, const String& name)
- : HTMLCollection(document.get(), type, document->nameCollectionInfo(type, name))
+HTMLNameCollection::HTMLNameCollection(Document* document, CollectionType type, const AtomicString& name)
+ : HTMLCollection(document, type, 0, /* retainBaseNode */ false)
, m_name(name)
{
}
Modified: trunk/Source/WebCore/html/HTMLNameCollection.h (103864 => 103865)
--- trunk/Source/WebCore/html/HTMLNameCollection.h 2012-01-01 00:50:00 UTC (rev 103864)
+++ trunk/Source/WebCore/html/HTMLNameCollection.h 2012-01-01 00:56:01 UTC (rev 103865)
@@ -24,25 +24,26 @@
#define HTMLNameCollection_h
#include "HTMLCollection.h"
-#include "PlatformString.h"
+#include <wtf/text/AtomicString.h>
+
namespace WebCore {
class Document;
class HTMLNameCollection : public HTMLCollection {
public:
- static PassRefPtr<HTMLNameCollection> create(PassRefPtr<Document> document, CollectionType type, const String& name)
+ static PassRefPtr<HTMLNameCollection> create(Document* document, CollectionType type, const AtomicString& name)
{
return adoptRef(new HTMLNameCollection(document, type, name));
}
-
+
private:
- HTMLNameCollection(PassRefPtr<Document>, CollectionType, const String& name);
+ HTMLNameCollection(Document*, CollectionType, const AtomicString& name);
- virtual Element* itemAfter(Element*) const;
+ virtual Element* itemAfter(Element*) const OVERRIDE;
- String m_name;
+ AtomicString m_name;
};
}