<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[175380] trunk/Source/WebCore</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/175380">175380</a></dd>
<dt>Author</dt> <dd>cdumez@apple.com</dd>
<dt>Date</dt> <dd>2014-10-30 14:25:30 -0700 (Thu, 30 Oct 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>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&lt;HTMLMediaElement&gt;() instead of
   (is&lt;HTMLVideoElement&gt;() || is&lt;HTMLAudioElement&gt;()) 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()
2. 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:</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreaccessibilityAccessibilityRenderObjectcpp">trunk/Source/WebCore/accessibility/AccessibilityRenderObject.cpp</a></li>
<li><a href="#trunkSourceWebCorecssCSSDefaultStyleSheetscpp">trunk/Source/WebCore/css/CSSDefaultStyleSheets.cpp</a></li>
<li><a href="#trunkSourceWebCoredommake_namespl">trunk/Source/WebCore/dom/make_names.pl</a></li>
<li><a href="#trunkSourceWebCorehtmlHTMLAudioElementh">trunk/Source/WebCore/html/HTMLAudioElement.h</a></li>
<li><a href="#trunkSourceWebCorehtmlHTMLImageLoadercpp">trunk/Source/WebCore/html/HTMLImageLoader.cpp</a></li>
<li><a href="#trunkSourceWebCorehtmlHTMLTagNamesin">trunk/Source/WebCore/html/HTMLTagNames.in</a></li>
<li><a href="#trunkSourceWebCorehtmlHTMLVideoElementh">trunk/Source/WebCore/html/HTMLVideoElement.h</a></li>
<li><a href="#trunkSourceWebCorepageChromeClienth">trunk/Source/WebCore/page/ChromeClient.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (175379 => 175380)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2014-10-30 21:17:30 UTC (rev 175379)
+++ trunk/Source/WebCore/ChangeLog        2014-10-30 21:25:30 UTC (rev 175380)
</span><span class="lines">@@ -1,3 +1,48 @@
</span><ins>+2014-10-30  Chris Dumez  &lt;cdumez@apple.com&gt;
+
+        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&lt;HTMLMediaElement&gt;() instead of
+           (is&lt;HTMLVideoElement&gt;() || is&lt;HTMLAudioElement&gt;()) 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()
+        2. 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:
+
</ins><span class="cx"> 2014-10-30  Myles C. Maxfield  &lt;mmaxfield@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Migrate ComplexTextControllerCoreText to use SPI instead of WKSI
</span></span></pre></div>
<a id="trunkSourceWebCoreaccessibilityAccessibilityRenderObjectcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/accessibility/AccessibilityRenderObject.cpp (175379 => 175380)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/accessibility/AccessibilityRenderObject.cpp        2014-10-30 21:17:30 UTC (rev 175379)
+++ trunk/Source/WebCore/accessibility/AccessibilityRenderObject.cpp        2014-10-30 21:25:30 UTC (rev 175380)
</span><span class="lines">@@ -44,6 +44,7 @@
</span><span class="cx"> #include &quot;FrameLoader.h&quot;
</span><span class="cx"> #include &quot;FrameSelection.h&quot;
</span><span class="cx"> #include &quot;HTMLAreaElement.h&quot;
</span><ins>+#include &quot;HTMLAudioElement.h&quot;
</ins><span class="cx"> #include &quot;HTMLFormElement.h&quot;
</span><span class="cx"> #include &quot;HTMLFrameElementBase.h&quot;
</span><span class="cx"> #include &quot;HTMLImageElement.h&quot;
</span><span class="lines">@@ -57,6 +58,7 @@
</span><span class="cx"> #include &quot;HTMLSelectElement.h&quot;
</span><span class="cx"> #include &quot;HTMLTableElement.h&quot;
</span><span class="cx"> #include &quot;HTMLTextAreaElement.h&quot;
</span><ins>+#include &quot;HTMLVideoElement.h&quot;
</ins><span class="cx"> #include &quot;HitTestRequest.h&quot;
</span><span class="cx"> #include &quot;HitTestResult.h&quot;
</span><span class="cx"> #include &quot;Image.h&quot;
</span></span></pre></div>
<a id="trunkSourceWebCorecssCSSDefaultStyleSheetscpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/css/CSSDefaultStyleSheets.cpp (175379 => 175380)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/css/CSSDefaultStyleSheets.cpp        2014-10-30 21:17:30 UTC (rev 175379)
+++ trunk/Source/WebCore/css/CSSDefaultStyleSheets.cpp        2014-10-30 21:25:30 UTC (rev 175380)
</span><span class="lines">@@ -177,7 +177,7 @@
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(VIDEO)
</span><del>-    if (!mediaControlsStyleSheet &amp;&amp; (is&lt;HTMLVideoElement&gt;(element) || is&lt;HTMLAudioElement&gt;(element))) {
</del><ins>+    if (!mediaControlsStyleSheet &amp;&amp; is&lt;HTMLMediaElement&gt;(element)) {
</ins><span class="cx">         String mediaRules = RenderTheme::themeForPage(element.document().page())-&gt;mediaControlsStyleSheet();
</span><span class="cx">         if (mediaRules.isEmpty())
</span><span class="cx">             mediaRules = String(mediaControlsUserAgentStyleSheet, sizeof(mediaControlsUserAgentStyleSheet)) + RenderTheme::themeForPage(element.document().page())-&gt;extraMediaControlsStyleSheet();
</span></span></pre></div>
<a id="trunkSourceWebCoredommake_namespl"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/make_names.pl (175379 => 175380)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/make_names.pl        2014-10-30 21:17:30 UTC (rev 175379)
+++ trunk/Source/WebCore/dom/make_names.pl        2014-10-30 21:25:30 UTC (rev 175380)
</span><span class="lines">@@ -194,6 +194,7 @@
</span><span class="cx">         'wrapperOnlyIfMediaIsAvailable' =&gt; 0,
</span><span class="cx">         'conditional' =&gt; 0,
</span><span class="cx">         'runtimeConditional' =&gt; 0,
</span><ins>+        'customTypeHelper' =&gt; 0,
</ins><span class="cx">     );
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -634,10 +635,12 @@
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     for my $class (sort keys %classToTags) {
</span><ins>+        my $name = $classToTags{$class}[0];
+        next if $parsedTags{$name}{customTypeHelper};
</ins><span class="cx">         # Skip classes that map to more than 1 tag.
</span><span class="cx">         my $tagCount = scalar @{$classToTags{$class}};
</span><span class="cx">         next if $tagCount &gt; 1;
</span><del>-        my $name = $classToTags{$class}[0];
</del><ins>+
</ins><span class="cx">         print F &lt;&lt;END
</span><span class="cx"> namespace WebCore {
</span><span class="cx"> class $class;
</span></span></pre></div>
<a id="trunkSourceWebCorehtmlHTMLAudioElementh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/HTMLAudioElement.h (175379 => 175380)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/HTMLAudioElement.h        2014-10-30 21:17:30 UTC (rev 175379)
+++ trunk/Source/WebCore/html/HTMLAudioElement.h        2014-10-30 21:25:30 UTC (rev 175380)
</span><span class="lines">@@ -45,7 +45,13 @@
</span><span class="cx">     virtual MediaSession::MediaType presentationType() const override { return MediaSession::Audio; }
</span><span class="cx"> };
</span><span class="cx"> 
</span><del>-} //namespace
</del><ins>+} // namespace WebCore
</ins><span class="cx"> 
</span><del>-#endif
-#endif
</del><ins>+SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::HTMLAudioElement)
+    static bool isType(const WebCore::HTMLMediaElement&amp; element) { return element.hasTagName(WebCore::HTMLNames::audioTag); }
+    static bool isType(const WebCore::Element&amp; element) { return is&lt;WebCore::HTMLMediaElement&gt;(element) &amp;&amp; isType(downcast&lt;WebCore::HTMLMediaElement&gt;(element)); }
+    static bool isType(const WebCore::Node&amp; node) { return is&lt;WebCore::HTMLMediaElement&gt;(node) &amp;&amp; isType(downcast&lt;WebCore::HTMLMediaElement&gt;(node)); }
+SPECIALIZE_TYPE_TRAITS_END()
+
+#endif // ENABLE(VIDEO)
+#endif // HTMLAudioElement_h
</ins></span></pre></div>
<a id="trunkSourceWebCorehtmlHTMLImageLoadercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/HTMLImageLoader.cpp (175379 => 175380)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/HTMLImageLoader.cpp        2014-10-30 21:17:30 UTC (rev 175379)
+++ trunk/Source/WebCore/html/HTMLImageLoader.cpp        2014-10-30 21:25:30 UTC (rev 175380)
</span><span class="lines">@@ -29,6 +29,7 @@
</span><span class="cx"> #include &quot;HTMLNames.h&quot;
</span><span class="cx"> #include &quot;HTMLObjectElement.h&quot;
</span><span class="cx"> #include &quot;HTMLParserIdioms.h&quot;
</span><ins>+#include &quot;HTMLVideoElement.h&quot;
</ins><span class="cx"> #include &quot;Settings.h&quot;
</span><span class="cx"> 
</span><span class="cx"> #include &quot;JSDOMWindowBase.h&quot;
</span></span></pre></div>
<a id="trunkSourceWebCorehtmlHTMLTagNamesin"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/HTMLTagNames.in (175379 => 175380)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/HTMLTagNames.in        2014-10-30 21:17:30 UTC (rev 175379)
+++ trunk/Source/WebCore/html/HTMLTagNames.in        2014-10-30 21:25:30 UTC (rev 175380)
</span><span class="lines">@@ -11,7 +11,7 @@
</span><span class="cx"> area
</span><span class="cx"> article interfaceName=HTMLElement
</span><span class="cx"> aside interfaceName=HTMLElement
</span><del>-audio wrapperOnlyIfMediaIsAvailable, conditional=VIDEO, constructorNeedsCreatedByParser
</del><ins>+audio wrapperOnlyIfMediaIsAvailable, conditional=VIDEO, constructorNeedsCreatedByParser, customTypeHelper
</ins><span class="cx"> b interfaceName=HTMLElement
</span><span class="cx"> base
</span><span class="cx"> basefont interfaceName=HTMLBaseFontElement
</span><span class="lines">@@ -134,7 +134,7 @@
</span><span class="cx"> u interfaceName=HTMLElement
</span><span class="cx"> ul interfaceName=HTMLUListElement
</span><span class="cx"> var interfaceName=HTMLElement
</span><del>-video wrapperOnlyIfMediaIsAvailable, conditional=VIDEO, constructorNeedsCreatedByParser
</del><ins>+video wrapperOnlyIfMediaIsAvailable, conditional=VIDEO, constructorNeedsCreatedByParser, customTypeHelper
</ins><span class="cx"> wbr interfaceName=HTMLElement
</span><span class="cx"> xmp interfaceName=HTMLPreElement
</span><span class="cx"> noscript interfaceName=HTMLElement
</span></span></pre></div>
<a id="trunkSourceWebCorehtmlHTMLVideoElementh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/HTMLVideoElement.h (175379 => 175380)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/HTMLVideoElement.h        2014-10-30 21:17:30 UTC (rev 175379)
+++ trunk/Source/WebCore/html/HTMLVideoElement.h        2014-10-30 21:25:30 UTC (rev 175380)
</span><span class="lines">@@ -104,7 +104,13 @@
</span><span class="cx">     AtomicString m_defaultPosterURL;
</span><span class="cx"> };
</span><span class="cx"> 
</span><del>-} //namespace
</del><ins>+} // namespace WebCore
</ins><span class="cx"> 
</span><del>-#endif
-#endif
</del><ins>+SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::HTMLVideoElement)
+    static bool isType(const WebCore::HTMLMediaElement&amp; element) { return element.hasTagName(WebCore::HTMLNames::videoTag); }
+    static bool isType(const WebCore::Element&amp; element) { return is&lt;WebCore::HTMLMediaElement&gt;(element) &amp;&amp; isType(downcast&lt;WebCore::HTMLMediaElement&gt;(element)); }
+    static bool isType(const WebCore::Node&amp; node) { return is&lt;WebCore::HTMLMediaElement&gt;(node) &amp;&amp; isType(downcast&lt;WebCore::HTMLMediaElement&gt;(node)); }
+SPECIALIZE_TYPE_TRAITS_END()
+
+#endif // ENABLE(VIDEO)
+#endif // HTMLVideoElement_h
</ins></span></pre></div>
<a id="trunkSourceWebCorepageChromeClienth"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/ChromeClient.h (175379 => 175380)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/ChromeClient.h        2014-10-30 21:17:30 UTC (rev 175379)
+++ trunk/Source/WebCore/page/ChromeClient.h        2014-10-30 21:25:30 UTC (rev 175380)
</span><span class="lines">@@ -75,6 +75,7 @@
</span><span class="cx"> class GraphicsLayer;
</span><span class="cx"> class GraphicsLayerFactory;
</span><span class="cx"> class HTMLInputElement;
</span><ins>+class HTMLVideoElement;
</ins><span class="cx"> class HitTestResult;
</span><span class="cx"> class IntRect;
</span><span class="cx"> class NavigationAction;
</span></span></pre>
</div>
</div>

</body>
</html>