<!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>[184916] 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/184916">184916</a></dd>
<dt>Author</dt> <dd>eric.carlson@apple.com</dd>
<dt>Date</dt> <dd>2015-05-27 13:33:09 -0700 (Wed, 27 May 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>[Mac] short-circuit MIME type lookup when possible
https://bugs.webkit.org/show_bug.cgi?id=145362

Reviewed by Jer Noble.

* platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:
(WebCore::isUnsupportedMIMEType): Renamed from unsupportedMIMEType. Convert type to lower case
once instead of calling equalIgnoringCase many times.
(WebCore::staticMIMETypeList): Renamed from staticMimeTypeCache. Initialize static set in a lambda,
using an array of C strings in a loop.
(WebCore::avfMIMETypes): Renamed from avfMimeTypeCache. Initialize static set in a lambda.
(WebCore::MediaPlayerPrivateAVFoundationObjC::getSupportedTypes): avfMimeTypeCache -&gt; avfMIMETypes.
(WebCore::keySystemIsSupported): equalIgnoringCase -&gt; equalIgnoringASCIICase.
(WebCore::MediaPlayerPrivateAVFoundationObjC::supportsType): Ditto.
(WebCore::MediaPlayerPrivateAVFoundationObjC::supportsKeySystem): unsupportedMIMEType -&gt; 
isUnsupportedMIMEType, equalIgnoringCase -&gt; equalIgnoringASCIICase, staticMimeTypeCache -&gt; 
staticMIMETypeList, avfMimeTypeCache -&gt; avfMIMETypes.
(WebCore::unsupportedMIMEType): Deleted.
(WebCore::staticMimeTypeCache): Deleted.
(WebCore::avfMimeTypeCache): Deleted.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsavfoundationobjcMediaPlayerPrivateAVFoundationObjCmm">trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (184915 => 184916)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2015-05-27 20:14:05 UTC (rev 184915)
+++ trunk/Source/WebCore/ChangeLog        2015-05-27 20:33:09 UTC (rev 184916)
</span><span class="lines">@@ -3,6 +3,29 @@
</span><span class="cx">         [Mac] short-circuit MIME type lookup when possible
</span><span class="cx">         https://bugs.webkit.org/show_bug.cgi?id=145362
</span><span class="cx"> 
</span><ins>+        Reviewed by Jer Noble.
+
+        * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:
+        (WebCore::isUnsupportedMIMEType): Renamed from unsupportedMIMEType. Convert type to lower case
+        once instead of calling equalIgnoringCase many times.
+        (WebCore::staticMIMETypeList): Renamed from staticMimeTypeCache. Initialize static set in a lambda,
+        using an array of C strings in a loop.
+        (WebCore::avfMIMETypes): Renamed from avfMimeTypeCache. Initialize static set in a lambda.
+        (WebCore::MediaPlayerPrivateAVFoundationObjC::getSupportedTypes): avfMimeTypeCache -&gt; avfMIMETypes.
+        (WebCore::keySystemIsSupported): equalIgnoringCase -&gt; equalIgnoringASCIICase.
+        (WebCore::MediaPlayerPrivateAVFoundationObjC::supportsType): Ditto.
+        (WebCore::MediaPlayerPrivateAVFoundationObjC::supportsKeySystem): unsupportedMIMEType -&gt; 
+        isUnsupportedMIMEType, equalIgnoringCase -&gt; equalIgnoringASCIICase, staticMimeTypeCache -&gt; 
+        staticMIMETypeList, avfMimeTypeCache -&gt; avfMIMETypes.
+        (WebCore::unsupportedMIMEType): Deleted.
+        (WebCore::staticMimeTypeCache): Deleted.
+        (WebCore::avfMimeTypeCache): Deleted.
+
+2015-05-27  Eric Carlson  &lt;eric.carlson@apple.com&gt;
+
+        [Mac] short-circuit MIME type lookup when possible
+        https://bugs.webkit.org/show_bug.cgi?id=145362
+
</ins><span class="cx">         Reviewed by Dean Jackson.
</span><span class="cx"> 
</span><span class="cx">         * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsavfoundationobjcMediaPlayerPrivateAVFoundationObjCmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm (184915 => 184916)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm        2015-05-27 20:14:05 UTC (rev 184915)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm        2015-05-27 20:33:09 UTC (rev 184916)
</span><span class="lines">@@ -1545,87 +1545,92 @@
</span><span class="cx">     }
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-static bool unsupportedMIMEType(const String&amp; type)
</del><ins>+static bool isUnsupportedMIMEType(const String&amp; type)
</ins><span class="cx"> {
</span><ins>+    String lowerCaseType = type.convertToASCIILowercase();
+
</ins><span class="cx">     // AVFoundation will return non-video MIME types which it claims to support, but which we
</span><span class="cx">     // do not support in the &lt;video&gt; element. Reject all non video/, audio/, and application/ types.
</span><del>-    if (!type.startsWith(&quot;video/&quot;, false) &amp;&amp; !type.startsWith(&quot;audio/&quot;, false) &amp;&amp; !type.startsWith(&quot;application/&quot;, false))
</del><ins>+    if (!lowerCaseType.startsWith(&quot;video/&quot;) &amp;&amp; !lowerCaseType.startsWith(&quot;audio/&quot;) &amp;&amp; !lowerCaseType.startsWith(&quot;application/&quot;))
</ins><span class="cx">         return true;
</span><span class="cx"> 
</span><span class="cx">     // Reject types we know AVFoundation does not support that sites commonly ask about.
</span><del>-    if (equalIgnoringCase(type, &quot;video/webm&quot;) || equalIgnoringCase(type, &quot;audio/webm&quot;) || equalIgnoringCase(type, &quot;video/x-webm&quot;))
</del><ins>+    if (lowerCaseType == &quot;video/webm&quot; || lowerCaseType == &quot;audio/webm&quot; || lowerCaseType == &quot;video/x-webm&quot;)
</ins><span class="cx">         return true;
</span><span class="cx"> 
</span><del>-    if (equalIgnoringCase(type, &quot;video/x-flv&quot;))
</del><ins>+    if (lowerCaseType == &quot;video/x-flv&quot;)
</ins><span class="cx">         return true;
</span><span class="cx"> 
</span><del>-    if (equalIgnoringCase(type, &quot;audio/ogg&quot;) || equalIgnoringCase(type, &quot;video/ogg&quot;) || equalIgnoringCase(type, &quot;application/ogg&quot;))
</del><ins>+    if (lowerCaseType == &quot;audio/ogg&quot; || lowerCaseType == &quot;video/ogg&quot; || lowerCaseType == &quot;application/ogg&quot;)
</ins><span class="cx">         return true;
</span><span class="cx"> 
</span><del>-    if (equalIgnoringCase(type, &quot;video/h264&quot;))
</del><ins>+    if (lowerCaseType == &quot;video/h264&quot;)
</ins><span class="cx">         return true;
</span><span class="cx"> 
</span><span class="cx">     return false;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-static HashSet&lt;String&gt;&amp; staticMimeTypeCache()
</del><ins>+static const HashSet&lt;String&gt;&amp; staticMIMETypeList()
</ins><span class="cx"> {
</span><del>-    static NeverDestroyed&lt;HashSet&lt;String&gt;&gt; cache;
-    static bool typeListInitialized = false;
</del><ins>+    static NeverDestroyed&lt;HashSet&lt;String&gt;&gt; cache = [] () {
+        HashSet&lt;String&gt; types;
</ins><span class="cx"> 
</span><del>-    if (typeListInitialized)
-        return cache;
-    typeListInitialized = true;
</del><ins>+        static const char* typeNames[] = {
+            &quot;application/vnd.apple.mpegurl&quot;,
+            &quot;application/x-mpegurl&quot;,
+            &quot;audio/3gpp&quot;,
+            &quot;audio/aac&quot;,
+            &quot;audio/aacp&quot;,
+            &quot;audio/aiff&quot;,
+            &quot;audio/basic&quot;,
+            &quot;audio/mp3&quot;,
+            &quot;audio/mp4&quot;,
+            &quot;audio/mpeg&quot;,
+            &quot;audio/mpeg3&quot;,
+            &quot;audio/mpegurl&quot;,
+            &quot;audio/mpg&quot;,
+            &quot;audio/wav&quot;,
+            &quot;audio/wave&quot;,
+            &quot;audio/x-aac&quot;,
+            &quot;audio/x-aiff&quot;,
+            &quot;audio/x-m4a&quot;,
+            &quot;audio/x-mpegurl&quot;,
+            &quot;audio/x-wav&quot;,
+            &quot;video/3gpp&quot;,
+            &quot;video/3gpp2&quot;,
+            &quot;video/mp4&quot;,
+            &quot;video/mpeg&quot;,
+            &quot;video/mpeg2&quot;,
+            &quot;video/mpg&quot;,
+            &quot;video/quicktime&quot;,
+            &quot;video/x-m4v&quot;,
+            &quot;video/x-mpeg&quot;,
+            &quot;video/x-mpg&quot;,
+        };
+        for (size_t i = 0; i &lt; WTF_ARRAY_LENGTH(typeNames); ++i)
+            types.add(typeNames[i]);
</ins><span class="cx"> 
</span><del>-    cache.get().add(&quot;application/vnd.apple.mpegurl&quot;);
-    cache.get().add(&quot;application/x-mpegurl&quot;);
-    cache.get().add(&quot;audio/3gpp&quot;);
-    cache.get().add(&quot;audio/aac&quot;);
-    cache.get().add(&quot;audio/aacp&quot;);
-    cache.get().add(&quot;audio/aiff&quot;);
-    cache.get().add(&quot;audio/basic&quot;);
-    cache.get().add(&quot;audio/mp3&quot;);
-    cache.get().add(&quot;audio/mp4&quot;);
-    cache.get().add(&quot;audio/mpeg&quot;);
-    cache.get().add(&quot;audio/mpeg3&quot;);
-    cache.get().add(&quot;audio/mpegurl&quot;);
-    cache.get().add(&quot;audio/mpg&quot;);
-    cache.get().add(&quot;audio/wav&quot;);
-    cache.get().add(&quot;audio/wave&quot;);
-    cache.get().add(&quot;audio/x-aac&quot;);
-    cache.get().add(&quot;audio/x-aiff&quot;);
-    cache.get().add(&quot;audio/x-m4a&quot;);
-    cache.get().add(&quot;audio/x-mpegurl&quot;);
-    cache.get().add(&quot;audio/x-wav&quot;);
-    cache.get().add(&quot;video/3gpp&quot;);
-    cache.get().add(&quot;video/3gpp2&quot;);
-    cache.get().add(&quot;video/mp4&quot;);
-    cache.get().add(&quot;video/mpeg&quot;);
-    cache.get().add(&quot;video/mpeg2&quot;);
-    cache.get().add(&quot;video/mpg&quot;);
-    cache.get().add(&quot;video/quicktime&quot;);
-    cache.get().add(&quot;video/x-m4v&quot;);
-    cache.get().add(&quot;video/x-mpeg&quot;);
-    cache.get().add(&quot;video/x-mpg&quot;);
</del><ins>+        return types;
+    }();
</ins><span class="cx"> 
</span><span class="cx">     return cache;
</span><del>-} 
</del><ins>+}
</ins><span class="cx"> 
</span><del>-static HashSet&lt;String&gt;&amp; avfMimeTypeCache()
</del><ins>+static const HashSet&lt;String&gt;&amp; avfMIMETypes()
</ins><span class="cx"> {
</span><del>-    static NeverDestroyed&lt;HashSet&lt;String&gt;&gt; cache;
-    static bool typeListInitialized = false;
</del><ins>+    static NeverDestroyed&lt;HashSet&lt;String&gt;&gt; cache = [] () {
+        HashSet&lt;String&gt; types;
</ins><span class="cx"> 
</span><del>-    if (typeListInitialized)
-        return cache;
-    typeListInitialized = true;
</del><ins>+        NSArray *nsTypes = [AVURLAsset audiovisualMIMETypes];
+        for (NSString *mimeType in nsTypes)
+            types.add([mimeType lowercaseString]);
</ins><span class="cx"> 
</span><del>-    NSArray *types = [AVURLAsset audiovisualMIMETypes];
-    for (NSString *mimeType in types)
-        cache.get().add([mimeType lowercaseString]);
</del><ins>+        return types;
+    }();
</ins><span class="cx"> 
</span><ins>+    
</ins><span class="cx">     return cache;
</span><del>-} 
</del><ins>+}
</ins><span class="cx"> 
</span><span class="cx"> RetainPtr&lt;CGImageRef&gt; MediaPlayerPrivateAVFoundationObjC::createImageForTimeInRect(float time, const FloatRect&amp; rect)
</span><span class="cx"> {
</span><span class="lines">@@ -1651,13 +1656,13 @@
</span><span class="cx"> 
</span><span class="cx"> void MediaPlayerPrivateAVFoundationObjC::getSupportedTypes(HashSet&lt;String&gt;&amp; supportedTypes)
</span><span class="cx"> {
</span><del>-    supportedTypes = avfMimeTypeCache();
</del><ins>+    supportedTypes = avfMIMETypes();
</ins><span class="cx"> } 
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(ENCRYPTED_MEDIA) || ENABLE(ENCRYPTED_MEDIA_V2)
</span><span class="cx"> static bool keySystemIsSupported(const String&amp; keySystem)
</span><span class="cx"> {
</span><del>-    if (equalIgnoringCase(keySystem, &quot;com.apple.fps&quot;) || equalIgnoringCase(keySystem, &quot;com.apple.fps.1_0&quot;) || equalIgnoringCase(keySystem, &quot;org.w3c.clearkey&quot;))
</del><ins>+    if (equalIgnoringASCIICase(keySystem, &quot;com.apple.fps&quot;) || equalIgnoringASCIICase(keySystem, &quot;com.apple.fps.1_0&quot;) || equalIgnoringASCIICase(keySystem, &quot;org.w3c.clearkey&quot;))
</ins><span class="cx">         return true;
</span><span class="cx">     return false;
</span><span class="cx"> }
</span><span class="lines">@@ -1673,7 +1678,7 @@
</span><span class="cx">     //    If keySystem is null, continue to the next step.
</span><span class="cx">     if (!parameters.keySystem.isNull() &amp;&amp; !parameters.keySystem.isEmpty()) {
</span><span class="cx">         // &quot;Clear Key&quot; is only supported with HLS:
</span><del>-        if (equalIgnoringCase(parameters.keySystem, &quot;org.w3c.clearkey&quot;) &amp;&amp; !parameters.type.isEmpty() &amp;&amp; !equalIgnoringCase(parameters.type, &quot;application/x-mpegurl&quot;))
</del><ins>+        if (equalIgnoringASCIICase(parameters.keySystem, &quot;org.w3c.clearkey&quot;) &amp;&amp; !parameters.type.isEmpty() &amp;&amp; !equalIgnoringASCIICase(parameters.type, &quot;application/x-mpegurl&quot;))
</ins><span class="cx">             return MediaPlayer::IsNotSupported;
</span><span class="cx"> 
</span><span class="cx">         // If keySystem contains an unrecognized or unsupported Key System, return the empty string
</span><span class="lines">@@ -1692,10 +1697,10 @@
</span><span class="cx">         return MediaPlayer::IsNotSupported;
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><del>-    if (unsupportedMIMEType(parameters.type))
</del><ins>+    if (isUnsupportedMIMEType(parameters.type))
</ins><span class="cx">         return MediaPlayer::IsNotSupported;
</span><span class="cx"> 
</span><del>-    if (!staticMimeTypeCache().contains(parameters.type) &amp;&amp; !avfMimeTypeCache().contains(parameters.type))
</del><ins>+    if (!staticMIMETypeList().contains(parameters.type) &amp;&amp; !avfMIMETypes().contains(parameters.type))
</ins><span class="cx">         return MediaPlayer::IsNotSupported;
</span><span class="cx"> 
</span><span class="cx">     // The spec says:
</span><span class="lines">@@ -1712,16 +1717,16 @@
</span><span class="cx"> #if ENABLE(ENCRYPTED_MEDIA) || ENABLE(ENCRYPTED_MEDIA_V2)
</span><span class="cx">     if (!keySystem.isEmpty()) {
</span><span class="cx">         // &quot;Clear Key&quot; is only supported with HLS:
</span><del>-        if (equalIgnoringCase(keySystem, &quot;org.w3c.clearkey&quot;) &amp;&amp; !mimeType.isEmpty() &amp;&amp; !equalIgnoringCase(mimeType, &quot;application/x-mpegurl&quot;))
</del><ins>+        if (equalIgnoringASCIICase(keySystem, &quot;org.w3c.clearkey&quot;) &amp;&amp; !mimeType.isEmpty() &amp;&amp; !equalIgnoringASCIICase(mimeType, &quot;application/x-mpegurl&quot;))
</ins><span class="cx">             return MediaPlayer::IsNotSupported;
</span><span class="cx"> 
</span><span class="cx">         if (!keySystemIsSupported(keySystem))
</span><span class="cx">             return false;
</span><span class="cx"> 
</span><del>-        if (!mimeType.isEmpty() &amp;&amp; unsupportedMIMEType(mimeType))
</del><ins>+        if (!mimeType.isEmpty() &amp;&amp; isUnsupportedMIMEType(mimeType))
</ins><span class="cx">             return false;
</span><span class="cx"> 
</span><del>-        if (!mimeType.isEmpty() &amp;&amp; !staticMimeTypeCache().contains(mimeType) &amp;&amp; !avfMimeTypeCache().contains(mimeType))
</del><ins>+        if (!mimeType.isEmpty() &amp;&amp; !staticMIMETypeList().contains(mimeType) &amp;&amp; !avfMIMETypes().contains(mimeType))
</ins><span class="cx">             return false;
</span><span class="cx"> 
</span><span class="cx">         return true;
</span></span></pre>
</div>
</div>

</body>
</html>