Title: [175788] trunk/Source/WebCore
Revision
175788
Author
cdu...@apple.com
Date
2014-11-08 21:59:52 -0800 (Sat, 08 Nov 2014)

Log Message

Call faster HTMLElement::hasTagName() in HTMLCollection
https://bugs.webkit.org/show_bug.cgi?id=138529

Reviewed by Darin Adler.

Call faster HTMLElement::hasTagName() in HTMLCollection instead of
slower Node::hasTagName() by restructuring the code a bit to
distinguish collection that deal only with HTMLElements from others.

No new tests, no behavior change.

* html/HTMLCollection.cpp:
(WebCore::isMatchingHTMLElement):
(WebCore::isMatchingElement):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (175787 => 175788)


--- trunk/Source/WebCore/ChangeLog	2014-11-09 05:46:59 UTC (rev 175787)
+++ trunk/Source/WebCore/ChangeLog	2014-11-09 05:59:52 UTC (rev 175788)
@@ -1,5 +1,22 @@
 2014-11-08  Chris Dumez  <cdu...@apple.com>
 
+        Call faster HTMLElement::hasTagName() in HTMLCollection
+        https://bugs.webkit.org/show_bug.cgi?id=138529
+
+        Reviewed by Darin Adler.
+
+        Call faster HTMLElement::hasTagName() in HTMLCollection instead of
+        slower Node::hasTagName() by restructuring the code a bit to
+        distinguish collection that deal only with HTMLElements from others.
+
+        No new tests, no behavior change.
+
+        * html/HTMLCollection.cpp:
+        (WebCore::isMatchingHTMLElement):
+        (WebCore::isMatchingElement):
+
+2014-11-08  Chris Dumez  <cdu...@apple.com>
+
         Move isEmptyValue() logic from HTMLInputElement to TextFieldInputType
         https://bugs.webkit.org/show_bug.cgi?id=138538
 

Modified: trunk/Source/WebCore/html/HTMLCollection.cpp (175787 => 175788)


--- trunk/Source/WebCore/html/HTMLCollection.cpp	2014-11-09 05:46:59 UTC (rev 175787)
+++ trunk/Source/WebCore/html/HTMLCollection.cpp	2014-11-09 05:59:52 UTC (rev 175788)
@@ -169,13 +169,9 @@
     return ownerNode();
 }
 
-inline bool isMatchingElement(const HTMLCollection& htmlCollection, Element& element)
+inline bool isMatchingHTMLElement(const HTMLCollection& collection, HTMLElement& element)
 {
-    CollectionType type = htmlCollection.type();
-    if (!element.isHTMLElement() && !(type == DocAll || type == NodeChildren || type == WindowNamedItems))
-        return false;
-
-    switch (type) {
+    switch (collection.type()) {
     case DocImages:
         return element.hasTagName(imgTag);
     case DocScripts:
@@ -209,13 +205,11 @@
         return (element.hasTagName(aTag) || element.hasTagName(areaTag)) && element.fastHasAttribute(hrefAttr);
     case DocAnchors:
         return element.hasTagName(aTag) && element.fastHasAttribute(nameAttr);
+    case DocumentNamedItems:
+        return static_cast<const DocumentNameCollection&>(collection).elementMatches(element);
     case DocAll:
     case NodeChildren:
-        return true;
-    case DocumentNamedItems:
-        return static_cast<const DocumentNameCollection&>(htmlCollection).elementMatches(element);
     case WindowNamedItems:
-        return static_cast<const WindowNameCollection&>(htmlCollection).elementMatches(element);
     case FormControls:
     case TableRows:
         break;
@@ -224,6 +218,21 @@
     return false;
 }
 
+inline bool isMatchingElement(const HTMLCollection& collection, Element& element)
+{
+    // Collection types that deal with any type of Elements, not just HTMLElements.
+    switch (collection.type()) {
+    case DocAll:
+    case NodeChildren:
+        return true;
+    case WindowNamedItems:
+        return static_cast<const WindowNameCollection&>(collection).elementMatches(element);
+    default:
+        // Collection types that only deal with HTMLElements.
+        return is<HTMLElement>(element) && isMatchingHTMLElement(collection, downcast<HTMLElement>(element));
+    }
+}
+
 static Element* previousElement(ContainerNode& base, Element* previous, bool onlyIncludeDirectChildren)
 {
     return onlyIncludeDirectChildren ? ElementTraversal::previousSibling(previous) : ElementTraversal::previous(previous, &base);
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to