Changeset 175788 in webkit


Ignore:
Timestamp:
Nov 8, 2014, 9:59:52 PM (11 years ago)
Author:
Chris Dumez
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):

Location:
trunk/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r175787 r175788  
     12014-11-08  Chris Dumez  <cdumez@apple.com>
     2
     3        Call faster HTMLElement::hasTagName() in HTMLCollection
     4        https://bugs.webkit.org/show_bug.cgi?id=138529
     5
     6        Reviewed by Darin Adler.
     7
     8        Call faster HTMLElement::hasTagName() in HTMLCollection instead of
     9        slower Node::hasTagName() by restructuring the code a bit to
     10        distinguish collection that deal only with HTMLElements from others.
     11
     12        No new tests, no behavior change.
     13
     14        * html/HTMLCollection.cpp:
     15        (WebCore::isMatchingHTMLElement):
     16        (WebCore::isMatchingElement):
     17
    1182014-11-08  Chris Dumez  <cdumez@apple.com>
    219
  • trunk/Source/WebCore/html/HTMLCollection.cpp

    r174225 r175788  
    170170}
    171171
    172 inline bool isMatchingElement(const HTMLCollection& htmlCollection, Element& element)
    173 {
    174     CollectionType type = htmlCollection.type();
    175     if (!element.isHTMLElement() && !(type == DocAll || type == NodeChildren || type == WindowNamedItems))
    176         return false;
    177 
    178     switch (type) {
     172inline bool isMatchingHTMLElement(const HTMLCollection& collection, HTMLElement& element)
     173{
     174    switch (collection.type()) {
    179175    case DocImages:
    180176        return element.hasTagName(imgTag);
     
    210206    case DocAnchors:
    211207        return element.hasTagName(aTag) && element.fastHasAttribute(nameAttr);
     208    case DocumentNamedItems:
     209        return static_cast<const DocumentNameCollection&>(collection).elementMatches(element);
     210    case DocAll:
     211    case NodeChildren:
     212    case WindowNamedItems:
     213    case FormControls:
     214    case TableRows:
     215        break;
     216    }
     217    ASSERT_NOT_REACHED();
     218    return false;
     219}
     220
     221inline bool isMatchingElement(const HTMLCollection& collection, Element& element)
     222{
     223    // Collection types that deal with any type of Elements, not just HTMLElements.
     224    switch (collection.type()) {
    212225    case DocAll:
    213226    case NodeChildren:
    214227        return true;
    215     case DocumentNamedItems:
    216         return static_cast<const DocumentNameCollection&>(htmlCollection).elementMatches(element);
    217228    case WindowNamedItems:
    218         return static_cast<const WindowNameCollection&>(htmlCollection).elementMatches(element);
    219     case FormControls:
    220     case TableRows:
    221         break;
    222     }
    223     ASSERT_NOT_REACHED();
    224     return false;
     229        return static_cast<const WindowNameCollection&>(collection).elementMatches(element);
     230    default:
     231        // Collection types that only deal with HTMLElements.
     232        return is<HTMLElement>(element) && isMatchingHTMLElement(collection, downcast<HTMLElement>(element));
     233    }
    225234}
    226235
Note: See TracChangeset for help on using the changeset viewer.