Changeset 175380 in webkit


Ignore:
Timestamp:
Oct 30, 2014 2:25:30 PM (9 years ago)
Author:
Chris Dumez
Message:

Optimize HTMLVideoElement / HTMLAudioElement type checks a bit
https://bugs.webkit.org/show_bug.cgi?id=138202

Reviewed by Benjamin Poulain.

Optimize HTMLVideoElement / HTMLAudioElement type checks a bit by:

  1. Using is<HTMLMediaElement>() instead of
(is<HTMLVideoElement>()
is<HTMLAudioElement>()) if the caller is

interested in both video and audio elements. This is faster because
it ends up doing:

  • virtual call to Element::isMediaElement()

instead of

  • Node::isHTMLElement() + virtual call to HTMLElement::isHTMLUnknownElement() + 2 * HTMLElement::hasTagName()
  1. Updating HTMLVideoElement / HTMLAudioElement type traits specializations to:
    • Avoid doing any virtual function call if the input type is an HTMLMediaElement (which is common in the code base).
    • Speed up check if the input is an Element by doing:
      • virtual call to Element::isMediaElement() + HTMLElement::hasTagName()
      instead of
      • Node::isHTMLElement() + virtual call to !HTMLElement::isHTMLUnknownElement() + HTMLElement::hasTagName()
      The speed stays the same if the input is a Node or an HTMLElement.

No new tests, no behavior change.

  • css/CSSDefaultStyleSheets.cpp:

(WebCore::CSSDefaultStyleSheets::ensureDefaultStyleSheetsForElement):

  • dom/make_names.pl:

(defaultTagPropertyHash):
(printTypeHelpers):

  • html/HTMLAudioElement.h:

(isType):

  • html/HTMLImageLoader.cpp:
  • html/HTMLTagNames.in:
  • html/HTMLVideoElement.h:

(isType):

  • page/ChromeClient.h:
Location:
trunk/Source/WebCore
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r175379 r175380  
     12014-10-30  Chris Dumez  <cdumez@apple.com>
     2
     3        Optimize HTMLVideoElement / HTMLAudioElement type checks a bit
     4        https://bugs.webkit.org/show_bug.cgi?id=138202
     5
     6        Reviewed by Benjamin Poulain.
     7
     8        Optimize HTMLVideoElement / HTMLAudioElement type checks a bit by:
     9        1. Using is<HTMLMediaElement>() instead of
     10           (is<HTMLVideoElement>() || is<HTMLAudioElement>()) if the caller is
     11           interested in both video and audio elements. This is faster because
     12           it ends up doing:
     13               - virtual call to Element::isMediaElement()
     14           instead of
     15               - Node::isHTMLElement() +
     16                 virtual call to HTMLElement::isHTMLUnknownElement() +
     17                 2 * HTMLElement::hasTagName()
     18        2. Updating HTMLVideoElement / HTMLAudioElement type traits
     19           specializations to:
     20           - Avoid doing any virtual function call if the input type is an
     21             HTMLMediaElement (which is common in the code base).
     22           - Speed up check if the input is an Element by doing:
     23               - virtual call to Element::isMediaElement() +
     24                 HTMLElement::hasTagName()
     25             instead of
     26               - Node::isHTMLElement() +
     27                 virtual call to !HTMLElement::isHTMLUnknownElement() +
     28                 HTMLElement::hasTagName()
     29             The speed stays the same if the input is a Node or an HTMLElement.
     30
     31        No new tests, no behavior change.
     32
     33        * css/CSSDefaultStyleSheets.cpp:
     34        (WebCore::CSSDefaultStyleSheets::ensureDefaultStyleSheetsForElement):
     35        * dom/make_names.pl:
     36        (defaultTagPropertyHash):
     37        (printTypeHelpers):
     38        * html/HTMLAudioElement.h:
     39        (isType):
     40        * html/HTMLImageLoader.cpp:
     41        * html/HTMLTagNames.in:
     42        * html/HTMLVideoElement.h:
     43        (isType):
     44        * page/ChromeClient.h:
     45
    1462014-10-30  Myles C. Maxfield  <mmaxfield@apple.com>
    247
  • trunk/Source/WebCore/accessibility/AccessibilityRenderObject.cpp

    r175237 r175380  
    4545#include "FrameSelection.h"
    4646#include "HTMLAreaElement.h"
     47#include "HTMLAudioElement.h"
    4748#include "HTMLFormElement.h"
    4849#include "HTMLFrameElementBase.h"
     
    5859#include "HTMLTableElement.h"
    5960#include "HTMLTextAreaElement.h"
     61#include "HTMLVideoElement.h"
    6062#include "HitTestRequest.h"
    6163#include "HitTestResult.h"
  • trunk/Source/WebCore/css/CSSDefaultStyleSheets.cpp

    r174084 r175380  
    178178
    179179#if ENABLE(VIDEO)
    180     if (!mediaControlsStyleSheet && (is<HTMLVideoElement>(element) || is<HTMLAudioElement>(element))) {
     180    if (!mediaControlsStyleSheet && is<HTMLMediaElement>(element)) {
    181181        String mediaRules = RenderTheme::themeForPage(element.document().page())->mediaControlsStyleSheet();
    182182        if (mediaRules.isEmpty())
  • trunk/Source/WebCore/dom/make_names.pl

    r174375 r175380  
    195195        'conditional' => 0,
    196196        'runtimeConditional' => 0,
     197        'customTypeHelper' => 0,
    197198    );
    198199}
     
    635636
    636637    for my $class (sort keys %classToTags) {
     638        my $name = $classToTags{$class}[0];
     639        next if $parsedTags{$name}{customTypeHelper};
    637640        # Skip classes that map to more than 1 tag.
    638641        my $tagCount = scalar @{$classToTags{$class}};
    639642        next if $tagCount > 1;
    640         my $name = $classToTags{$class}[0];
     643
    641644        print F <<END
    642645namespace WebCore {
  • trunk/Source/WebCore/html/HTMLAudioElement.h

    r173969 r175380  
    4646};
    4747
    48 } //namespace
     48} // namespace WebCore
    4949
    50 #endif
    51 #endif
     50SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::HTMLAudioElement)
     51    static bool isType(const WebCore::HTMLMediaElement& element) { return element.hasTagName(WebCore::HTMLNames::audioTag); }
     52    static bool isType(const WebCore::Element& element) { return is<WebCore::HTMLMediaElement>(element) && isType(downcast<WebCore::HTMLMediaElement>(element)); }
     53    static bool isType(const WebCore::Node& node) { return is<WebCore::HTMLMediaElement>(node) && isType(downcast<WebCore::HTMLMediaElement>(node)); }
     54SPECIALIZE_TYPE_TRAITS_END()
     55
     56#endif // ENABLE(VIDEO)
     57#endif // HTMLAudioElement_h
  • trunk/Source/WebCore/html/HTMLImageLoader.cpp

    r173980 r175380  
    3030#include "HTMLObjectElement.h"
    3131#include "HTMLParserIdioms.h"
     32#include "HTMLVideoElement.h"
    3233#include "Settings.h"
    3334
  • trunk/Source/WebCore/html/HTMLTagNames.in

    r174050 r175380  
    1212article interfaceName=HTMLElement
    1313aside interfaceName=HTMLElement
    14 audio wrapperOnlyIfMediaIsAvailable, conditional=VIDEO, constructorNeedsCreatedByParser
     14audio wrapperOnlyIfMediaIsAvailable, conditional=VIDEO, constructorNeedsCreatedByParser, customTypeHelper
    1515b interfaceName=HTMLElement
    1616base
     
    135135ul interfaceName=HTMLUListElement
    136136var interfaceName=HTMLElement
    137 video wrapperOnlyIfMediaIsAvailable, conditional=VIDEO, constructorNeedsCreatedByParser
     137video wrapperOnlyIfMediaIsAvailable, conditional=VIDEO, constructorNeedsCreatedByParser, customTypeHelper
    138138wbr interfaceName=HTMLElement
    139139xmp interfaceName=HTMLPreElement
  • trunk/Source/WebCore/html/HTMLVideoElement.h

    r175328 r175380  
    105105};
    106106
    107 } //namespace
     107} // namespace WebCore
    108108
    109 #endif
    110 #endif
     109SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::HTMLVideoElement)
     110    static bool isType(const WebCore::HTMLMediaElement& element) { return element.hasTagName(WebCore::HTMLNames::videoTag); }
     111    static bool isType(const WebCore::Element& element) { return is<WebCore::HTMLMediaElement>(element) && isType(downcast<WebCore::HTMLMediaElement>(element)); }
     112    static bool isType(const WebCore::Node& node) { return is<WebCore::HTMLMediaElement>(node) && isType(downcast<WebCore::HTMLMediaElement>(node)); }
     113SPECIALIZE_TYPE_TRAITS_END()
     114
     115#endif // ENABLE(VIDEO)
     116#endif // HTMLVideoElement_h
  • trunk/Source/WebCore/page/ChromeClient.h

    r175279 r175380  
    7676class GraphicsLayerFactory;
    7777class HTMLInputElement;
     78class HTMLVideoElement;
    7879class HitTestResult;
    7980class IntRect;
Note: See TracChangeset for help on using the changeset viewer.