JSC/HTMLCollection: Optimize canGetItemsForName().
authorkling@webkit.org <kling@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 18 Dec 2011 22:21:05 +0000 (22:21 +0000)
committerkling@webkit.org <kling@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 18 Dec 2011 22:21:05 +0000 (22:21 +0000)
<http://webkit.org/b/74806>

Reviewed by Sam Weinig.

Add HTMLCollection::hasNamedItem(name) and use that in the JSC bindings'
canGetItemsForName() instead of fetching the list of named items just to
check if it's empty or not.

* bindings/js/JSHTMLAllCollectionCustom.cpp:
(WebCore::JSHTMLAllCollection::canGetItemsForName):
* bindings/js/JSHTMLCollectionCustom.cpp:
(WebCore::JSHTMLCollection::canGetItemsForName):
* html/HTMLCollection.cpp:
(WebCore::HTMLCollection::hasNamedItem):
* html/HTMLCollection.h:

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

Source/WebCore/ChangeLog
Source/WebCore/bindings/js/JSHTMLAllCollectionCustom.cpp
Source/WebCore/bindings/js/JSHTMLCollectionCustom.cpp
Source/WebCore/html/HTMLCollection.cpp
Source/WebCore/html/HTMLCollection.h

index e2cbf2d..b9aa6c6 100644 (file)
@@ -1,3 +1,22 @@
+2011-12-18  Andreas Kling  <kling@webkit.org>
+
+        JSC/HTMLCollection: Optimize canGetItemsForName().
+        <http://webkit.org/b/74806>
+
+        Reviewed by Sam Weinig.
+
+        Add HTMLCollection::hasNamedItem(name) and use that in the JSC bindings'
+        canGetItemsForName() instead of fetching the list of named items just to
+        check if it's empty or not.
+
+        * bindings/js/JSHTMLAllCollectionCustom.cpp:
+        (WebCore::JSHTMLAllCollection::canGetItemsForName):
+        * bindings/js/JSHTMLCollectionCustom.cpp:
+        (WebCore::JSHTMLCollection::canGetItemsForName):
+        * html/HTMLCollection.cpp:
+        (WebCore::HTMLCollection::hasNamedItem):
+        * html/HTMLCollection.h:
+
 2011-12-18  Sam Weinig  <sam@webkit.org>
 
         Spruce up PlatformWheelEvent a bit
index ab01c5d..a54374e 100644 (file)
@@ -101,9 +101,7 @@ CallType JSHTMLAllCollection::getCallData(JSCell*, CallData& callData)
 
 bool JSHTMLAllCollection::canGetItemsForName(ExecState*, HTMLAllCollection* collection, const Identifier& propertyName)
 {
-    Vector<RefPtr<Node> > namedItems;
-    collection->namedItems(identifierToAtomicString(propertyName), namedItems);
-    return !namedItems.isEmpty();
+    return collection->hasNamedItem(identifierToAtomicString(propertyName));
 }
 
 JSValue JSHTMLAllCollection::nameGetter(ExecState* exec, JSValue slotBase, const Identifier& propertyName)
index 5b9a8e1..494c1ba 100644 (file)
@@ -60,9 +60,7 @@ static JSValue getNamedItems(ExecState* exec, JSHTMLCollection* collection, cons
 
 bool JSHTMLCollection::canGetItemsForName(ExecState*, HTMLCollection* collection, const Identifier& propertyName)
 {
-    Vector<RefPtr<Node> > namedItems;
-    collection->namedItems(identifierToAtomicString(propertyName), namedItems);
-    return !namedItems.isEmpty();
+    return collection->hasNamedItem(identifierToAtomicString(propertyName));
 }
 
 JSValue JSHTMLCollection::nameGetter(ExecState* exec, JSValue slotBase, const Identifier& propertyName)
index 2131b9a..6cd8dec 100644 (file)
@@ -331,6 +331,28 @@ void HTMLCollection::updateNameCache() const
     m_info->hasNameCache = true;
 }
 
+bool HTMLCollection::hasNamedItem(const AtomicString& name) const
+{
+    if (name.isEmpty())
+        return false;
+
+    resetCollectionInfo();
+    updateNameCache();
+    m_info->checkConsistency();
+
+    if (Vector<Element*>* idCache = m_info->idCache.get(name.impl())) {
+        if (!idCache->isEmpty())
+            return true;
+    }
+
+    if (Vector<Element*>* nameCache = m_info->nameCache.get(name.impl())) {
+        if (!nameCache->isEmpty())
+            return true;
+    }
+
+    return false;
+}
+
 void HTMLCollection::namedItems(const AtomicString& name, Vector<RefPtr<Node> >& result) const
 {
     ASSERT(result.isEmpty());
index d683c9f..a1dd1ff 100644 (file)
@@ -53,6 +53,7 @@ public:
 
     Node* firstItem() const;
 
+    bool hasNamedItem(const AtomicString& name) const;
     void namedItems(const AtomicString& name, Vector<RefPtr<Node> >&) const;
 
     PassRefPtr<NodeList> tags(const String&);