Title: [174695] trunk/Source/WebCore
Revision
174695
Author
[email protected]
Date
2014-10-14 12:24:27 -0700 (Tue, 14 Oct 2014)

Log Message

[Mac] Avoid unnecessary dictionary lookup in ImageSource::isSizeAvailable()
https://bugs.webkit.org/show_bug.cgi?id=137701

Reviewed by Simon Fraser.

The CG implementation of ImageSource::isSizeAvailable() was looking up
both the width and the height keys in the dictionary before determining
if the size is available. We can abort early and return false if the
first key (the width) is missing, thus avoiding an extra dictionary
lookup in this case.

This is a small win but ImageSource::isSizeAvailable() is called quite
frequently during page loads

No new tests, no behavior change.

* platform/graphics/cg/ImageSourceCG.cpp:
(WebCore::ImageSource::isSizeAvailable):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (174694 => 174695)


--- trunk/Source/WebCore/ChangeLog	2014-10-14 19:22:41 UTC (rev 174694)
+++ trunk/Source/WebCore/ChangeLog	2014-10-14 19:24:27 UTC (rev 174695)
@@ -1,3 +1,24 @@
+2014-10-14  Chris Dumez  <[email protected]>
+
+        [Mac] Avoid unnecessary dictionary lookup in ImageSource::isSizeAvailable()
+        https://bugs.webkit.org/show_bug.cgi?id=137701
+
+        Reviewed by Simon Fraser.
+
+        The CG implementation of ImageSource::isSizeAvailable() was looking up
+        both the width and the height keys in the dictionary before determining
+        if the size is available. We can abort early and return false if the
+        first key (the width) is missing, thus avoiding an extra dictionary
+        lookup in this case.
+
+        This is a small win but ImageSource::isSizeAvailable() is called quite
+        frequently during page loads
+
+        No new tests, no behavior change.
+
+        * platform/graphics/cg/ImageSourceCG.cpp:
+        (WebCore::ImageSource::isSizeAvailable):
+
 2014-10-14  Myles C. Maxfield  <[email protected]>
 
         Remove unnecessary logging from SimpleFontData

Modified: trunk/Source/WebCore/platform/graphics/cg/ImageSourceCG.cpp (174694 => 174695)


--- trunk/Source/WebCore/platform/graphics/cg/ImageSourceCG.cpp	2014-10-14 19:22:41 UTC (rev 174694)
+++ trunk/Source/WebCore/platform/graphics/cg/ImageSourceCG.cpp	2014-10-14 19:24:27 UTC (rev 174695)
@@ -181,20 +181,16 @@
 
 bool ImageSource::isSizeAvailable()
 {
-    bool result = false;
-    CGImageSourceStatus imageSourceStatus = CGImageSourceGetStatus(m_decoder);
-
     // Ragnaros yells: TOO SOON! You have awakened me TOO SOON, Executus!
-    if (imageSourceStatus >= kCGImageStatusIncomplete) {
-        RetainPtr<CFDictionaryRef> image0Properties = adoptCF(CGImageSourceCopyPropertiesAtIndex(m_decoder, 0, imageSourceOptions().get()));
-        if (image0Properties) {
-            CFNumberRef widthNumber = (CFNumberRef)CFDictionaryGetValue(image0Properties.get(), kCGImagePropertyPixelWidth);
-            CFNumberRef heightNumber = (CFNumberRef)CFDictionaryGetValue(image0Properties.get(), kCGImagePropertyPixelHeight);
-            result = widthNumber && heightNumber;
-        }
-    }
-    
-    return result;
+    if (CGImageSourceGetStatus(m_decoder) < kCGImageStatusIncomplete)
+        return false;
+
+    RetainPtr<CFDictionaryRef> image0Properties = adoptCF(CGImageSourceCopyPropertiesAtIndex(m_decoder, 0, imageSourceOptions().get()));
+    if (!image0Properties)
+        return false;
+
+    return CFDictionaryGetValue(image0Properties.get(), kCGImagePropertyPixelWidth)
+        && CFDictionaryGetValue(image0Properties.get(), kCGImagePropertyPixelHeight);
 }
 
 static ImageOrientation orientationFromProperties(CFDictionaryRef imageProperties)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to