Reviewed by Darin.
authorap <ap@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 24 Jun 2006 12:53:57 +0000 (12:53 +0000)
committerap <ap@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 24 Jun 2006 12:53:57 +0000 (12:53 +0000)
        - http://bugzilla.opendarwin.org/show_bug.cgi?id=8177
        Javascript search incredibly slow

        No change in functionality, thus no test.

        Use info sharing for named collections, too. Moved shared HTMLCollection infos from HTMLDocument
        to Document.  Renamed collection types to use the preferred WebKit style. Replaced direct
        HTMLCollection creation with using accessors from Document in a few places.

        * bindings/objc/DOMHTML.mm:
        (-[DOMHTMLElement children]):
        (-[DOMHTMLDocument images]):
        (-[DOMHTMLDocument applets]):
        (-[DOMHTMLDocument links]):
        (-[DOMHTMLDocument forms]):
        (-[DOMHTMLDocument anchors]):
        (-[DOMHTMLMapElement areas]):
        (-[DOMHTMLTableSectionElement rows]):
        (-[DOMHTMLTableElement rows]):
        (-[DOMHTMLTableElement tBodies]):
        (-[DOMHTMLTableRowElement cells]):
        * dom/Document.cpp:
        (WebCore::Document::images):
        (WebCore::Document::applets):
        (WebCore::Document::embeds):
        (WebCore::Document::objects):
        (WebCore::Document::scripts):
        (WebCore::Document::links):
        (WebCore::Document::forms):
        (WebCore::Document::anchors):
        (WebCore::Document::all):
        (WebCore::Document::windowNamedItems):
        (WebCore::Document::documentNamedItems):
        (WebCore::Document::nameCollectionInfo):
        * dom/Document.h:
        (WebCore::Document::collectionInfo):
        * html/HTMLCollection.cpp:
        (WebCore::HTMLCollection::HTMLCollection):
        (WebCore::HTMLCollection::traverseNextItem):
        (WebCore::HTMLCollection::checkForNameMatch):
        (WebCore::HTMLCollection::updateNameCache):
        * html/HTMLCollection.h:
        (WebCore::HTMLCollection::):
        * html/HTMLDocument.h:
        * html/HTMLElement.cpp:
        (WebCore::HTMLElement::children):
        * html/HTMLMapElement.cpp:
        (WebCore::HTMLMapElement::areas):
        * html/HTMLNameCollection.h:
        * html/HTMLNameCollection.cpp:
        (WebCore::HTMLNameCollection::HTMLNameCollection):
        (WebCore::HTMLNameCollection::traverseNextItem):
        * html/HTMLFormCollection.cpp:
        * html/HTMLOptionsCollection.cpp:
        (WebCore::HTMLOptionsCollection::HTMLOptionsCollection):
        * html/HTMLSelectElement.h:
        (WebCore::HTMLSelectElement::collectionInfo):
        * html/HTMLTableElement.cpp:
        (WebCore::HTMLTableElement::rows):
        (WebCore::HTMLTableElement::tBodies):
        * html/HTMLTableRowElement.cpp:
        (WebCore::HTMLTableRowElement::cells):
        * html/HTMLTableSectionElement.cpp:
        (WebCore::HTMLTableSectionElement::rows):
        * kwq/WebCoreAXObject.mm:
        (-[WebCoreAXObject accessibilityAttributeValue:]):
        * page/Frame.cpp:
        (WebCore::Frame::gotoAnchor):

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

19 files changed:
WebCore/ChangeLog
WebCore/bindings/objc/DOMHTML.mm
WebCore/dom/Document.cpp
WebCore/dom/Document.h
WebCore/html/HTMLCollection.cpp
WebCore/html/HTMLCollection.h
WebCore/html/HTMLDocument.h
WebCore/html/HTMLElement.cpp
WebCore/html/HTMLFormCollection.cpp
WebCore/html/HTMLMapElement.cpp
WebCore/html/HTMLNameCollection.cpp
WebCore/html/HTMLNameCollection.h
WebCore/html/HTMLOptionsCollection.cpp
WebCore/html/HTMLSelectElement.h
WebCore/html/HTMLTableElement.cpp
WebCore/html/HTMLTableRowElement.cpp
WebCore/html/HTMLTableSectionElement.cpp
WebCore/kwq/WebCoreAXObject.mm
WebCore/page/Frame.cpp

index 64d61d4ab9a89c75831807f81aedadc5782c8072..35fe0f7250d163d0d0100b00f502a1f2dd422c5b 100644 (file)
@@ -1,3 +1,76 @@
+2006-06-24  Alexey Proskuryakov  <ap@nypop.com>
+
+        Reviewed by Darin.
+
+        - http://bugzilla.opendarwin.org/show_bug.cgi?id=8177
+        Javascript search incredibly slow
+
+        No change in functionality, thus no test.
+
+        Use info sharing for named collections, too. Moved shared HTMLCollection infos from HTMLDocument 
+        to Document.  Renamed collection types to use the preferred WebKit style. Replaced direct
+        HTMLCollection creation with using accessors from Document in a few places.
+
+        * bindings/objc/DOMHTML.mm:
+        (-[DOMHTMLElement children]):
+        (-[DOMHTMLDocument images]):
+        (-[DOMHTMLDocument applets]):
+        (-[DOMHTMLDocument links]):
+        (-[DOMHTMLDocument forms]):
+        (-[DOMHTMLDocument anchors]):
+        (-[DOMHTMLMapElement areas]):
+        (-[DOMHTMLTableSectionElement rows]):
+        (-[DOMHTMLTableElement rows]):
+        (-[DOMHTMLTableElement tBodies]):
+        (-[DOMHTMLTableRowElement cells]):
+        * dom/Document.cpp:
+        (WebCore::Document::images):
+        (WebCore::Document::applets):
+        (WebCore::Document::embeds):
+        (WebCore::Document::objects):
+        (WebCore::Document::scripts):
+        (WebCore::Document::links):
+        (WebCore::Document::forms):
+        (WebCore::Document::anchors):
+        (WebCore::Document::all):
+        (WebCore::Document::windowNamedItems):
+        (WebCore::Document::documentNamedItems):
+        (WebCore::Document::nameCollectionInfo):
+        * dom/Document.h:
+        (WebCore::Document::collectionInfo):
+        * html/HTMLCollection.cpp:
+        (WebCore::HTMLCollection::HTMLCollection):
+        (WebCore::HTMLCollection::traverseNextItem):
+        (WebCore::HTMLCollection::checkForNameMatch):
+        (WebCore::HTMLCollection::updateNameCache):
+        * html/HTMLCollection.h:
+        (WebCore::HTMLCollection::):
+        * html/HTMLDocument.h:
+        * html/HTMLElement.cpp:
+        (WebCore::HTMLElement::children):
+        * html/HTMLMapElement.cpp:
+        (WebCore::HTMLMapElement::areas):
+        * html/HTMLNameCollection.h:
+        * html/HTMLNameCollection.cpp:
+        (WebCore::HTMLNameCollection::HTMLNameCollection):
+        (WebCore::HTMLNameCollection::traverseNextItem):
+        * html/HTMLFormCollection.cpp:
+        * html/HTMLOptionsCollection.cpp:
+        (WebCore::HTMLOptionsCollection::HTMLOptionsCollection):
+        * html/HTMLSelectElement.h:
+        (WebCore::HTMLSelectElement::collectionInfo):
+        * html/HTMLTableElement.cpp:
+        (WebCore::HTMLTableElement::rows):
+        (WebCore::HTMLTableElement::tBodies):
+        * html/HTMLTableRowElement.cpp:
+        (WebCore::HTMLTableRowElement::cells):
+        * html/HTMLTableSectionElement.cpp:
+        (WebCore::HTMLTableSectionElement::rows):
+        * kwq/WebCoreAXObject.mm:
+        (-[WebCoreAXObject accessibilityAttributeValue:]):
+        * page/Frame.cpp:
+        (WebCore::Frame::gotoAnchor):
+
 2006-06-24  Alexey Proskuryakov  <ap@nypop.com>
 
         Reviewed by Darin.
index 05fed24bd073c0a8ff6889dd6405fe840181c21e..05869e7b961584e49587e7f1204be3fd93658f03 100644 (file)
@@ -393,7 +393,7 @@ using namespace HTMLNames;
 
 - (DOMHTMLCollection *)children
 {
-    HTMLCollection *collection = new HTMLCollection([self _HTMLElement], HTMLCollection::NODE_CHILDREN);
+    HTMLCollection *collection = new HTMLCollection([self _HTMLElement], HTMLCollection::NodeChildren);
     return [DOMHTMLCollection _collectionWith:collection];
 }
 
@@ -453,31 +453,31 @@ using namespace HTMLNames;
 
 - (DOMHTMLCollection *)images
 {
-    HTMLCollection *collection = new HTMLCollection([self _HTMLDocument], HTMLCollection::DOC_IMAGES);
+    HTMLCollection *collection = new HTMLCollection([self _HTMLDocument], HTMLCollection::DocImages);
     return [DOMHTMLCollection _collectionWith:collection];
 }
 
 - (DOMHTMLCollection *)applets
 {
-    HTMLCollection *collection = new HTMLCollection([self _HTMLDocument], HTMLCollection::DOC_APPLETS);
+    HTMLCollection *collection = new HTMLCollection([self _HTMLDocument], HTMLCollection::DocApplets);
     return [DOMHTMLCollection _collectionWith:collection];
 }
 
 - (DOMHTMLCollection *)links
 {
-    HTMLCollection *collection = new HTMLCollection([self _HTMLDocument], HTMLCollection::DOC_LINKS);
+    HTMLCollection *collection = new HTMLCollection([self _HTMLDocument], HTMLCollection::DocLinks);
     return [DOMHTMLCollection _collectionWith:collection];
 }
 
 - (DOMHTMLCollection *)forms
 {
-    HTMLCollection *collection = new HTMLCollection([self _HTMLDocument], HTMLCollection::DOC_FORMS);
+    HTMLCollection *collection = new HTMLCollection([self _HTMLDocument], HTMLCollection::DocForms);
     return [DOMHTMLCollection _collectionWith:collection];
 }
 
 - (DOMHTMLCollection *)anchors
 {
-    HTMLCollection *collection = new HTMLCollection([self _HTMLDocument], HTMLCollection::DOC_ANCHORS);
+    HTMLCollection *collection = new HTMLCollection([self _HTMLDocument], HTMLCollection::DocAnchors);
     return [DOMHTMLCollection _collectionWith:collection];
 }
 
@@ -2838,7 +2838,7 @@ using namespace HTMLNames;
 
 - (DOMHTMLCollection *)areas
 {
-    HTMLCollection *collection = new HTMLCollection([self _mapElement], HTMLCollection::MAP_AREAS);
+    HTMLCollection *collection = new HTMLCollection([self _mapElement], HTMLCollection::MapAreas);
     return [DOMHTMLCollection _collectionWith:collection];
 }
 
@@ -3107,7 +3107,7 @@ using namespace HTMLNames;
 
 - (DOMHTMLCollection *)rows
 {
-    HTMLCollection *collection = new HTMLCollection([self _tableSectionElement], HTMLCollection::TABLE_ROWS);
+    HTMLCollection *collection = new HTMLCollection([self _tableSectionElement], HTMLCollection::TableRows);
     return [DOMHTMLCollection _collectionWith:collection];
 }
 
@@ -3176,13 +3176,13 @@ using namespace HTMLNames;
 
 - (DOMHTMLCollection *)rows
 {
-    HTMLCollection *collection = new HTMLCollection([self _tableElement], HTMLCollection::TABLE_ROWS);
+    HTMLCollection *collection = new HTMLCollection([self _tableElement], HTMLCollection::TableRows);
     return [DOMHTMLCollection _collectionWith:collection];
 }
 
 - (DOMHTMLCollection *)tBodies
 {
-    HTMLCollection *collection = new HTMLCollection([self _tableElement], HTMLCollection::TABLE_TBODIES);
+    HTMLCollection *collection = new HTMLCollection([self _tableElement], HTMLCollection::TableTBodies);
     return [DOMHTMLCollection _collectionWith:collection];
 }
 
@@ -3428,7 +3428,7 @@ using namespace HTMLNames;
 
 - (DOMHTMLCollection *)cells
 {
-    HTMLCollection *collection = new HTMLCollection([self _tableRowElement], HTMLCollection::TR_CELLS);
+    HTMLCollection *collection = new HTMLCollection([self _tableRowElement], HTMLCollection::TRCells);
     return [DOMHTMLCollection _collectionWith:collection];
 }
 
index 76116e883d8da20ed7f9e653112c474e1f314d56..452ba7d69ed81764535642ef46916c69417db52c 100644 (file)
@@ -3196,57 +3196,70 @@ void Document::removeRadioButtonGroup(AtomicStringImpl* name, HTMLFormElement *f
 
 PassRefPtr<HTMLCollection> Document::images()
 {
-    return new HTMLCollection(this, HTMLCollection::DOC_IMAGES);
+    return new HTMLCollection(this, HTMLCollection::DocImages);
 }
 
 PassRefPtr<HTMLCollection> Document::applets()
 {
-    return new HTMLCollection(this, HTMLCollection::DOC_APPLETS);
+    return new HTMLCollection(this, HTMLCollection::DocApplets);
 }
 
 PassRefPtr<HTMLCollection> Document::embeds()
 {
-    return new HTMLCollection(this, HTMLCollection::DOC_EMBEDS);
+    return new HTMLCollection(this, HTMLCollection::DocEmbeds);
 }
 
 PassRefPtr<HTMLCollection> Document::objects()
 {
-    return new HTMLCollection(this, HTMLCollection::DOC_OBJECTS);
+    return new HTMLCollection(this, HTMLCollection::DocObjects);
 }
 
 PassRefPtr<HTMLCollection> Document::scripts()
 {
-    return new HTMLCollection(this, HTMLCollection::DOC_SCRIPTS);
+    return new HTMLCollection(this, HTMLCollection::DocScripts);
 }
 
 PassRefPtr<HTMLCollection> Document::links()
 {
-    return new HTMLCollection(this, HTMLCollection::DOC_LINKS);
+    return new HTMLCollection(this, HTMLCollection::DocLinks);
 }
 
 PassRefPtr<HTMLCollection> Document::forms()
 {
-    return new HTMLCollection(this, HTMLCollection::DOC_FORMS);
+    return new HTMLCollection(this, HTMLCollection::DocForms);
 }
 
 PassRefPtr<HTMLCollection> Document::anchors()
 {
-    return new HTMLCollection(this, HTMLCollection::DOC_ANCHORS);
+    return new HTMLCollection(this, HTMLCollection::DocAnchors);
 }
 
 PassRefPtr<HTMLCollection> Document::all()
 {
-    return new HTMLCollection(this, HTMLCollection::DOC_ALL);
+    return new HTMLCollection(this, HTMLCollection::DocAll);
 }
 
 PassRefPtr<HTMLCollection> Document::windowNamedItems(const String &name)
 {
-    return new HTMLNameCollection(this, HTMLCollection::WINDOW_NAMED_ITEMS, name);
+    return new HTMLNameCollection(this, HTMLCollection::WindowNamedItems, name);
 }
 
 PassRefPtr<HTMLCollection> Document::documentNamedItems(const String &name)
 {
-    return new HTMLNameCollection(this, HTMLCollection::DOCUMENT_NAMED_ITEMS, name);
+    return new HTMLNameCollection(this, HTMLCollection::DocumentNamedItems, name);
+}
+
+HTMLCollection::CollectionInfo* Document::nameCollectionInfo(HTMLCollection::Type type, const String& name)
+{
+    HashMap<AtomicStringImpl*, HTMLCollection::CollectionInfo>& map = m_nameCollectionInfo[type - HTMLCollection::UnnamedCollectionTypes];
+    
+    AtomicString atomicName(name);
+    
+    HashMap<AtomicStringImpl*, HTMLCollection::CollectionInfo>::iterator iter = map.find(atomicName.impl());
+    if (iter == map.end())
+        iter = map.add(atomicName.impl(), HTMLCollection::CollectionInfo()).first;
+    
+    return &iter->second;
 }
 
 PassRefPtr<NameNodeList> Document::getElementsByName(const String &elementName)
index bdf5ca8b38d95641e0906ad4b89214f379d147e3..2ba3cc22b7ee4b5756058082546c8ef20f0a2341 100644 (file)
@@ -31,6 +31,7 @@
 #include "DeprecatedPtrList.h"
 #include "DeprecatedStringList.h"
 #include "DocumentMarker.h"
+#include "HTMLCollection.h"
 #include "StringHash.h"
 #include "Timer.h"
 #include <wtf/HashCountedSet.h>
@@ -66,7 +67,6 @@ namespace WebCore {
     class EventListener;
     class Frame;
     class FrameView;
-    class HTMLCollection;
     class HTMLDocument;
     class HTMLElement;
     class HTMLFormElement;
@@ -205,6 +205,15 @@ public:
     PassRefPtr<HTMLCollection> windowNamedItems(const String& name);
     PassRefPtr<HTMLCollection> documentNamedItems(const String& name);
 
+    HTMLCollection::CollectionInfo* collectionInfo(HTMLCollection::Type type)
+    {
+        if ((int)type < HTMLCollection::UnnamedCollectionTypes) 
+            return m_collectionInfo + type; 
+        return 0;
+    }
+
+    HTMLCollection::CollectionInfo* nameCollectionInfo(HTMLCollection::Type type, const String& name);
+
     // DOM methods overridden from  parent classes
 
     virtual String nodeName() const;
@@ -770,6 +779,9 @@ private:
     typedef HashMap<HTMLFormElement*, NameToInputMap*> FormToGroupMap;
     FormToGroupMap m_selectedRadioButtons;
     
+    HTMLCollection::CollectionInfo m_collectionInfo[HTMLCollection::UnnamedCollectionTypes];
+    HashMap<AtomicStringImpl*, HTMLCollection::CollectionInfo> m_nameCollectionInfo[HTMLCollection::CollectionTypes - HTMLCollection::UnnamedCollectionTypes];
+
 #if XPATH_SUPPORT
     RefPtr<XPathEvaluator> m_xpathEvaluator;
 #endif
index 88d79553f8ed744c29123f3977751f68448f0d9d..a8a3cf3dde3531919c61d8f9bc938b1deb558356 100644 (file)
@@ -33,15 +33,15 @@ namespace WebCore {
 
 using namespace HTMLNames;
 
-HTMLCollection::HTMLCollection(Node *_base, int _type)
+HTMLCollection::HTMLCollection(Node *_base, HTMLCollection::Type _type)
     : m_base(_base),
       type(_type),
       info(0),
       idsDone(false),
       m_ownsInfo(false)
 {
-    if (_base->isDocumentNode() && _base->document()->isHTMLDocument())
-        info = static_cast<HTMLDocument*>(_base->document())->collectionInfo(type);
+    if (_base->isDocumentNode())
+        info = _base->document()->collectionInfo(type);
 }
 
 HTMLCollection::~HTMLCollection()
@@ -98,7 +98,7 @@ Node *HTMLCollection::traverseNextItem(Node *current) const
 {
     assert(current);
 
-    if (type == NODE_CHILDREN && m_base.get() != current)
+    if (type == NodeChildren && m_base.get() != current)
         current = current->nextSibling();
     else
         current = current->traverseNextNode(m_base.get());
@@ -109,71 +109,71 @@ Node *HTMLCollection::traverseNextItem(Node *current) const
             bool deep = true;
             HTMLElement *e = static_cast<HTMLElement *>(current);
             switch(type) {
-            case DOC_IMAGES:
+            case DocImages:
                 if (e->hasLocalName(imgTag))
                     found = true;
                 break;
-            case DOC_SCRIPTS:
+            case DocScripts:
                 if (e->hasLocalName(scriptTag))
                     found = true;
                 break;
-            case DOC_FORMS:
+            case DocForms:
                 if(e->hasLocalName(formTag))
                     found = true;
                 break;
-            case TABLE_TBODIES:
+            case TableTBodies:
                 if (e->hasLocalName(tbodyTag))
                     found = true;
                 else if (e->hasLocalName(tableTag))
                     deep = false;
                 break;
-            case TR_CELLS:
+            case TRCells:
                 if (e->hasLocalName(tdTag) || e->hasLocalName(thTag))
                     found = true;
                 else if (e->hasLocalName(tableTag))
                     deep = false;
                 break;
-            case TABLE_ROWS:
-            case TSECTION_ROWS:
+            case TableRows:
+            case TSectionRows:
                 if (e->hasLocalName(trTag))
                     found = true;
                 else if (e->hasLocalName(tableTag))
                     deep = false;
                 break;
-            case SELECT_OPTIONS:
+            case SelectOptions:
                 if (e->hasLocalName(optionTag))
                     found = true;
                 break;
-            case MAP_AREAS:
+            case MapAreas:
                 if (e->hasLocalName(areaTag))
                     found = true;
                 break;
-            case DOC_APPLETS:   // all OBJECT and APPLET elements
+            case DocApplets:   // all OBJECT and APPLET elements
                 if (e->hasLocalName(objectTag) || e->hasLocalName(appletTag))
                     found = true;
                 break;
-            case DOC_EMBEDS:   // all EMBED elements
+            case DocEmbeds:   // all EMBED elements
                 if (e->hasLocalName(embedTag))
                     found = true;
                 break;
-            case DOC_OBJECTS:   // all OBJECT elements
+            case DocObjects:   // all OBJECT elements
                 if (e->hasLocalName(objectTag))
                     found = true;
                 break;
-            case DOC_LINKS:     // all A _and_ AREA elements with a value for href
+            case DocLinks:     // all A _and_ AREA elements with a value for href
                 if (e->hasLocalName(aTag) || e->hasLocalName(areaTag))
                     if (!e->getAttribute(hrefAttr).isNull())
                         found = true;
                 break;
-            case DOC_ANCHORS:      // all A elements with a value for name or an id attribute
+            case DocAnchors:      // all A elements with a value for name or an id attribute
                 if (e->hasLocalName(aTag))
                     if (!e->getAttribute(nameAttr).isNull())
                         found = true;
                 break;
-            case DOC_ALL:
+            case DocAll:
                 found = true;
                 break;
-            case NODE_CHILDREN:
+            case NodeChildren:
                 found = true;
                 deep = false;
                 break;
@@ -267,7 +267,7 @@ bool HTMLCollection::checkForNameMatch(Node *node, bool checkName, const String
         if (checkName) {
             // document.all returns only images, forms, applets, objects and embeds
             // by name (though everything by id)
-            if (type == DOC_ALL && 
+            if (type == DocAll && 
                 !(e->hasLocalName(imgTag) || e->hasLocalName(formTag) ||
                   e->hasLocalName(appletTag) || e->hasLocalName(objectTag) ||
                   e->hasLocalName(embedTag) || e->hasLocalName(inputTag)))
@@ -280,7 +280,7 @@ bool HTMLCollection::checkForNameMatch(Node *node, bool checkName, const String
         if (checkName) {
             // document.all returns only images, forms, applets, objects and embeds
             // by name (though everything by id)
-            if (type == DOC_ALL && 
+            if (type == DocAll && 
                 !(e->hasLocalName(imgTag) || e->hasLocalName(formTag) ||
                   e->hasLocalName(appletTag) || e->hasLocalName(objectTag) ||
                   e->hasLocalName(embedTag) || e->hasLocalName(inputTag)))
@@ -346,7 +346,7 @@ void HTMLCollection::updateNameCache() const
             idVector->append(n);
         }
         if (!nameAttrVal.isEmpty() && idAttrVal != nameAttrVal
-            && (type != DOC_ALL || 
+            && (type != DocAll || 
                 (e->hasLocalName(imgTag) || e->hasLocalName(formTag) ||
                  e->hasLocalName(appletTag) || e->hasLocalName(objectTag) ||
                  e->hasLocalName(embedTag) || e->hasLocalName(inputTag)))) {
index 1732cc3de6327035d92476fba8db1a93eed66f39..68b40776513864e51eb588ec3b250d205b9c4b75 100644 (file)
@@ -44,34 +44,35 @@ class HTMLCollection : public Shared<HTMLCollection>
 public:
     enum Type {
         // from JSHTMLDocument
-        DOC_IMAGES = 0, // all IMG elements in the document
-        DOC_APPLETS,   // all OBJECT and APPLET elements
-        DOC_EMBEDS,    // all EMBED elements
-        DOC_OBJECTS,   // all OBJECT elements
-        DOC_FORMS,     // all FORMS
-        DOC_LINKS,     // all A _and_ AREA elements with a value for href
-        DOC_ANCHORS,      // all A elements with a value for name
-        DOC_SCRIPTS,   // all SCRIPT element
+        DocImages = 0, // all IMG elements in the document
+        DocApplets,   // all OBJECT and APPLET elements
+        DocEmbeds,    // all EMBED elements
+        DocObjects,   // all OBJECT elements
+        DocForms,     // all FORMS
+        DocLinks,     // all A _and_ AREA elements with a value for href
+        DocAnchors,      // all A elements with a value for name
+        DocScripts,   // all SCRIPT element
         // from HTMLTable, HTMLTableSection, HTMLTableRow
-        TABLE_ROWS,    // all rows in this table or tablesection
-        TABLE_TBODIES, // all TBODY elements in this table
-        TSECTION_ROWS, // all rows elements in this table section
-        TR_CELLS,      // all CELLS in this row
+        TableRows,    // all rows in this table or tablesection
+        TableTBodies, // all TBODY elements in this table
+        TSectionRows, // all rows elements in this table section
+        TRCells,      // all CELLS in this row
         // from SELECT
-        SELECT_OPTIONS,
+        SelectOptions,
         // from HTMLMap
-        MAP_AREAS,
-        DOC_ALL,        // "all" elements (IE)
-        NODE_CHILDREN,   // first-level children (IE)
-        WINDOW_NAMED_ITEMS,
-        DOCUMENT_NAMED_ITEMS
+        MapAreas,
+        DocAll,        // "all" elements (IE)
+        NodeChildren,   // first-level children (IE)
+        WindowNamedItems,
+        DocumentNamedItems
     };
 
     enum {
-        NUM_CACHEABLE_TYPES = NODE_CHILDREN + 1
+        UnnamedCollectionTypes = NodeChildren + 1,
+        CollectionTypes = DocumentNamedItems + 1
     };
 
-    HTMLCollection(Node *_base, int _type);
+    HTMLCollection(Node *_base, HTMLCollection::Type _type);
     virtual ~HTMLCollection();
     
     unsigned length() const;
@@ -113,7 +114,7 @@ protected:
     // the base node, the collection refers to
     RefPtr<Node> m_base;
     // The collection list the following elements
-    int type;
+    Type type;
     mutable CollectionInfo *info;
 
     // For nextNamedItem()
index 564d4a7c958445550096a434d2247eaa2223fbb1..b8110e2062ffff35287060898880e0747bdc006a 100644 (file)
@@ -67,13 +67,6 @@ public:
     void removeDocExtraNamedItem(const String& name);
     bool hasDocExtraNamedItem(const String& name);
 
-    HTMLCollection::CollectionInfo* collectionInfo(int type)
-    { 
-        if (type < HTMLCollection::NUM_CACHEABLE_TYPES) 
-            return m_collection_info + type; 
-        return 0;
-    }
-
     typedef HashMap<StringImpl*, int> NameCountMap;
 
 protected:
@@ -81,8 +74,6 @@ protected:
     HTMLElement* htmlElement;
 
 private:
-    HTMLCollection::CollectionInfo m_collection_info[HTMLCollection::NUM_CACHEABLE_TYPES];
-
     NameCountMap namedItemCounts;
     NameCountMap docExtraNamedItemCounts;
 };
index 10d6d9f6cd10fedeab3d5d0f7552a6d9e31facdf..8344cef478ecf9a92a675926d483caeb35aee5f1 100644 (file)
@@ -607,7 +607,7 @@ void HTMLElement::setClassName(const String &value)
 
 PassRefPtr<HTMLCollection> HTMLElement::children()
 {
-    return new HTMLCollection(this, HTMLCollection::NODE_CHILDREN);
+    return new HTMLCollection(this, HTMLCollection::NodeChildren);
 }
 
 // DOM Section 1.1.1
index f77714b5eed837258ad6c104c92dfd494e83703c..042f3a8cf0f5632d2cb2b0351eadee2caf487abe 100644 (file)
@@ -38,7 +38,7 @@ using namespace HTMLNames;
 // calculation every time if anything has changed
 
 HTMLFormCollection::HTMLFormCollection(Node* _base)
-    : HTMLCollection(_base, 0)
+    : HTMLCollection(_base, HTMLCollection::Type(0))
 {
     HTMLFormElement *formBase = static_cast<HTMLFormElement*>(m_base.get());
     if (!formBase->collectionInfo)
index 661b460badb540790d100a7e5fb5afba6a5a3e4d..93dc0cce8d971d89bd0f273415da2eed7e1a7a5c 100644 (file)
@@ -85,7 +85,7 @@ void HTMLMapElement::parseMappedAttribute(MappedAttribute* attr)
 
 PassRefPtr<HTMLCollection> HTMLMapElement::areas()
 {
-    return new HTMLCollection(this, HTMLCollection::MAP_AREAS);
+    return new HTMLCollection(this, HTMLCollection::MapAreas);
 }
 
 String HTMLMapElement::name() const
index ca73641b508d51c63491b186b25236fb41b80444..e55789f040bb6dcb52dbfdd2c8395f21d3ce07fb 100644 (file)
@@ -25,8 +25,8 @@
 #include "config.h"
 #include "HTMLNameCollection.h"
 
-#include "Document.h"
 #include "Element.h"
+#include "HTMLDocument.h"
 #include "HTMLNames.h"
 #include "HTMLObjectElement.h"
 
@@ -34,15 +34,17 @@ namespace WebCore {
 
 using namespace HTMLNames;
 
-HTMLNameCollection::HTMLNameCollection(Document* base, int type, const String& name)
+HTMLNameCollection::HTMLNameCollection(Document* base, HTMLCollection::Type type, const String& name)
     : HTMLCollection(base, type)
     , m_name(name)
 {
+    ASSERT(!info);
+    info = base->nameCollectionInfo(type, name);
 }
 
 Node* HTMLNameCollection::traverseNextItem(Node* current) const
 {
-    assert(current);
+    ASSERT(current);
 
     current = current->traverseNextNode(m_base.get());
 
@@ -51,7 +53,7 @@ Node* HTMLNameCollection::traverseNextItem(Node* current) const
             bool found = false;
             Element* e = static_cast<Element*>(current);
             switch(type) {
-            case WINDOW_NAMED_ITEMS:
+            case WindowNamedItems:
                 // find only images, forms, applets, embeds and objects by name, 
                 // but anything by id
                 if (e->hasTagName(imgTag) ||
@@ -62,7 +64,7 @@ Node* HTMLNameCollection::traverseNextItem(Node* current) const
                     found = e->getAttribute(nameAttr) == m_name;
                 found |= e->getAttribute(idAttr) == m_name;
                 break;
-            case DOCUMENT_NAMED_ITEMS:
+            case DocumentNamedItems:
                 // find images, forms, applets, embeds, objects and iframes by name, 
                 // but only applets and object by id (this strange rule matches IE)
                 if (e->hasTagName(imgTag) ||
@@ -78,7 +80,7 @@ Node* HTMLNameCollection::traverseNextItem(Node* current) const
                         static_cast<HTMLObjectElement*>(e)->isDocNamedItem();
                 break;
             default:
-                assert(0);
+                ASSERT(0);
             }
 
             if (found)
index a490083d00a2b38539db9167b625817f1e0d070d..f34351f84433888f4edeaaab64cc1f298be32de0 100644 (file)
@@ -35,7 +35,7 @@ class Document;
 class HTMLNameCollection : public HTMLCollection
 {
 public:
-    HTMLNameCollection(Document*, int type, const String &name);
+    HTMLNameCollection(Document*, HTMLCollection::Type type, const String &name);
     
     virtual Node* traverseNextItem(Node*) const;
 
index 0ef5c2ad3ebfd895bc0f71f1c0f41771e4a0e6ca..67f7ed37f0e2deb69444ba9dea0997874677b2dc 100644 (file)
 namespace WebCore {
 
 HTMLOptionsCollection::HTMLOptionsCollection(HTMLSelectElement* select)
-    : HTMLCollection(select, SELECT_OPTIONS)
+    : HTMLCollection(select, SelectOptions)
 {
+    ASSERT(!info);
+
+    info = select->collectionInfo();
 }
 
 void HTMLOptionsCollection::setLength(unsigned, ExceptionCode& ec)
index 721105e43094151655cd6dec65ae68971ebf6759..1c327398f799c871c3adb0eb34f3b2c4b589677c 100644 (file)
@@ -27,6 +27,7 @@
 #define HTML_HTMLSelectElementImpl_H
 
 #include "HTMLGenericFormElement.h"
+#include "HTMLCollection.h"
 #include <wtf/Vector.h>
 
 namespace WebCore {
@@ -115,6 +116,8 @@ public:
 
     virtual Node* namedItem(const String &name, bool caseSensitive = true);
 
+    HTMLCollection::CollectionInfo* collectionInfo() { return &m_collectionInfo; }
+
 private:
     void recalcListItems();
 
@@ -123,6 +126,8 @@ private:
     int m_size;
     bool m_multiple;
     bool m_recalcListItems;
+    
+    HTMLCollection::CollectionInfo m_collectionInfo;
 };
 
 } //namespace
index e98eecffa8f286c51bc03bebfcbae11e713d8819..f08583fd719494f6f9c2b46a33acf6a6972958fb 100644 (file)
@@ -513,12 +513,12 @@ bool HTMLTableElement::isURLAttribute(Attribute *attr) const
 
 PassRefPtr<HTMLCollection> HTMLTableElement::rows()
 {
-    return new HTMLCollection(this, HTMLCollection::TABLE_ROWS);
+    return new HTMLCollection(this, HTMLCollection::TableRows);
 }
 
 PassRefPtr<HTMLCollection> HTMLTableElement::tBodies()
 {
-    return new HTMLCollection(this, HTMLCollection::TABLE_TBODIES);
+    return new HTMLCollection(this, HTMLCollection::TableTBodies);
 }
 
 String HTMLTableElement::align() const
index d74592f7e40dcfd4353910393857c939b5c0c19f..40b1fb59174b6d9df2a7002c9cde16579c1cb3ef 100644 (file)
@@ -163,7 +163,7 @@ void HTMLTableRowElement::deleteCell( int index, ExceptionCode& ec)
 
 PassRefPtr<HTMLCollection> HTMLTableRowElement::cells()
 {
-    return new HTMLCollection(this, HTMLCollection::TR_CELLS);
+    return new HTMLCollection(this, HTMLCollection::TRCells);
 }
 
 void HTMLTableRowElement::setCells(HTMLCollection *, ExceptionCode& ec)
index f6ce4a43c34cfc529c4bee5de148942c3cdfe2b0..fa81fad14dc2b7e9dab8dd6b9a4c66c5700e7b85 100644 (file)
@@ -155,7 +155,7 @@ void HTMLTableSectionElement::setVAlign(const String &value)
 
 PassRefPtr<HTMLCollection> HTMLTableSectionElement::rows()
 {
-    return new HTMLCollection(this, HTMLCollection::TABLE_ROWS);
+    return new HTMLCollection(this, HTMLCollection::TableRows);
 }
 
 }
index e9241ce42c86e2550e9304e183737932d129a64a..3b564af295ef1b3ce5e656ff30eaa64258ae6502 100644 (file)
@@ -803,8 +803,7 @@ static IntRect boundingBoxRect(RenderObject* obj)
     if (m_renderer->isRenderView()) {
         if ([attributeName isEqualToString: @"AXLinkUIElements"]) {
             NSMutableArray *links = [NSMutableArray arrayWithCapacity: 32];
-            HTMLCollection *coll = new HTMLCollection(m_renderer->document(), HTMLCollection::DOC_LINKS);
-            coll->ref();
+            RefPtr<HTMLCollection> coll = m_renderer->document()->links();
             Node *curr = coll->firstItem();
             while (curr) {
                 RenderObject *obj = curr->renderer();
@@ -816,7 +815,6 @@ static IntRect boundingBoxRect(RenderObject* obj)
                 }
                 curr = coll->nextItem();
             }
-            coll->deref();
             return links;
         }
         if ([attributeName isEqualToString: @"AXLoaded"])
index c30bb527b773f86f00ee7a80809389853d64c6ff..4765057e90f80b9ea700bbca07e6e371db286229 100644 (file)
@@ -1070,13 +1070,8 @@ bool Frame::gotoAnchor(const String& name)
     return false;
 
   Node *n = d->m_doc->getElementById(AtomicString(name));
-  if (!n) {
-    HTMLCollection *anchors =
-        new HTMLCollection(d->m_doc.get(), HTMLCollection::DOC_ANCHORS);
-    anchors->ref();
-    n = anchors->namedItem(name, !d->m_doc->inCompatMode());
-    anchors->deref();
-  }
+  if (!n)
+      n = d->m_doc->anchors()->namedItem(name, !d->m_doc->inCompatMode());
 
   d->m_doc->setCSSTarget(n); // Setting to null will clear the current target.