Bug 1201403 - streamline MacOSFontEntry::HasFontTable implementation. r=jfkthame
authorJohn Daggett <jdaggett@mozilla.com>
Mon, 07 Sep 2015 16:01:59 +0900
changeset 261218 219979d9d8ba499403ea8145b05b21a134121744
parent 261217 7941ce03a4bf4910ddb7bb7d989b53047b9893fc
child 261219 0dd0065b4a20304541044a5ed442124d911480c6
push id29339
push usercbook@mozilla.com
push dateTue, 08 Sep 2015 13:37:23 +0000
treeherdermozilla-central@b23b2fa33a9d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjfkthame
bugs1201403
milestone43.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1201403 - streamline MacOSFontEntry::HasFontTable implementation. r=jfkthame
gfx/thebes/gfxMacPlatformFontList.h
gfx/thebes/gfxMacPlatformFontList.mm
--- a/gfx/thebes/gfxMacPlatformFontList.h
+++ b/gfx/thebes/gfxMacPlatformFontList.h
@@ -62,16 +62,17 @@ protected:
     static void DestroyBlobFunc(void* aUserData);
 
     CGFontRef mFontRef; // owning reference to the CGFont, released on destruction
 
     bool mFontRefInitialized;
     bool mRequiresAAT;
     bool mIsCFF;
     bool mIsCFFInitialized;
+    nsTHashtable<nsUint32HashKey> mAvailableTables;
 };
 
 class gfxMacPlatformFontList : public gfxPlatformFontList {
 public:
     static gfxMacPlatformFontList* PlatformFontList() {
         return static_cast<gfxMacPlatformFontList*>(sPlatformFontList);
     }
 
--- a/gfx/thebes/gfxMacPlatformFontList.mm
+++ b/gfx/thebes/gfxMacPlatformFontList.mm
@@ -370,30 +370,36 @@ MacOSFontEntry::GetFontTable(uint32_t aT
     }
 
     return nullptr;
 }
 
 bool
 MacOSFontEntry::HasFontTable(uint32_t aTableTag)
 {
-    nsAutoreleasePool localPool;
+    if (mAvailableTables.Count() == 0) {
+        nsAutoreleasePool localPool;
 
-    CGFontRef fontRef = GetFontRef();
-    if (!fontRef) {
-        return false;
+        CGFontRef fontRef = GetFontRef();
+        if (!fontRef) {
+            return false;
+        }
+        CFArrayRef tags = ::CGFontCopyTableTags(fontRef);
+        if (!tags) {
+            return false;
+        }
+        int numTags = (int) ::CFArrayGetCount(tags);
+        for (int t = 0; t < numTags; t++) {
+            uint32_t tag = (uint32_t)(uintptr_t)::CFArrayGetValueAtIndex(tags, t);
+            mAvailableTables.PutEntry(tag);
+        }
+        ::CFRelease(tags);
     }
 
-    CFDataRef tableData = ::CGFontCopyTableForTag(fontRef, aTableTag);
-    if (!tableData) {
-        return false;
-    }
-
-    ::CFRelease(tableData);
-    return true;
+    return mAvailableTables.GetEntry(aTableTag);
 }
 
 void
 MacOSFontEntry::AddSizeOfIncludingThis(MallocSizeOf aMallocSizeOf,
                                        FontListSizes* aSizes) const
 {
     aSizes->mFontListSize += aMallocSizeOf(this);
     AddSizeOfExcludingThis(aMallocSizeOf, aSizes);