Title: [103190] trunk/Source/WebCore
- Revision
- 103190
- Author
- kl...@webkit.org
- Date
- 2011-12-18 14:21:05 -0800 (Sun, 18 Dec 2011)
Log Message
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:
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (103189 => 103190)
--- trunk/Source/WebCore/ChangeLog 2011-12-18 21:54:28 UTC (rev 103189)
+++ trunk/Source/WebCore/ChangeLog 2011-12-18 22:21:05 UTC (rev 103190)
@@ -1,3 +1,22 @@
+2011-12-18 Andreas Kling <kl...@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 <s...@webkit.org>
Spruce up PlatformWheelEvent a bit
Modified: trunk/Source/WebCore/bindings/js/JSHTMLAllCollectionCustom.cpp (103189 => 103190)
--- trunk/Source/WebCore/bindings/js/JSHTMLAllCollectionCustom.cpp 2011-12-18 21:54:28 UTC (rev 103189)
+++ trunk/Source/WebCore/bindings/js/JSHTMLAllCollectionCustom.cpp 2011-12-18 22:21:05 UTC (rev 103190)
@@ -101,9 +101,7 @@
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)
Modified: trunk/Source/WebCore/bindings/js/JSHTMLCollectionCustom.cpp (103189 => 103190)
--- trunk/Source/WebCore/bindings/js/JSHTMLCollectionCustom.cpp 2011-12-18 21:54:28 UTC (rev 103189)
+++ trunk/Source/WebCore/bindings/js/JSHTMLCollectionCustom.cpp 2011-12-18 22:21:05 UTC (rev 103190)
@@ -60,9 +60,7 @@
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)
Modified: trunk/Source/WebCore/html/HTMLCollection.cpp (103189 => 103190)
--- trunk/Source/WebCore/html/HTMLCollection.cpp 2011-12-18 21:54:28 UTC (rev 103189)
+++ trunk/Source/WebCore/html/HTMLCollection.cpp 2011-12-18 22:21:05 UTC (rev 103190)
@@ -331,6 +331,28 @@
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());
Modified: trunk/Source/WebCore/html/HTMLCollection.h (103189 => 103190)
--- trunk/Source/WebCore/html/HTMLCollection.h 2011-12-18 21:54:28 UTC (rev 103189)
+++ trunk/Source/WebCore/html/HTMLCollection.h 2011-12-18 22:21:05 UTC (rev 103190)
@@ -53,6 +53,7 @@
Node* firstItem() const;
+ bool hasNamedItem(const AtomicString& name) const;
void namedItems(const AtomicString& name, Vector<RefPtr<Node> >&) const;
PassRefPtr<NodeList> tags(const String&);
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes