FontDataCache should use Ref<Font> instead of a RefPtr<Font>
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 22 Sep 2018 07:56:20 +0000 (07:56 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 22 Sep 2018 07:56:20 +0000 (07:56 +0000)
https://bugs.webkit.org/show_bug.cgi?id=189861

Reviewed by Antti Koivisto.

* platform/graphics/FontCache.cpp:
(WebCore::FontCache::fontForPlatformData):
(WebCore::FontCache::purgeInactiveFontData):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@236383 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/FontCache.cpp

index 0b0ac13..e0dc704 100644 (file)
@@ -1,3 +1,14 @@
+2018-09-22  Chris Dumez  <cdumez@apple.com>
+
+        FontDataCache should use Ref<Font> instead of a RefPtr<Font>
+        https://bugs.webkit.org/show_bug.cgi?id=189861
+
+        Reviewed by Antti Koivisto.
+
+        * platform/graphics/FontCache.cpp:
+        (WebCore::FontCache::fontForPlatformData):
+        (WebCore::FontCache::purgeInactiveFontData):
+
 2018-09-21  Justin Michaud  <justin_michaud@apple.com>
 
         Implement initialValue support for CSS Custom Properties and Values API
index 4bbadfb..4b7c1ee 100644 (file)
@@ -283,7 +283,7 @@ struct FontDataCacheKeyTraits : WTF::GenericHashTraits<FontPlatformData> {
     }
 };
 
-typedef HashMap<FontPlatformData, RefPtr<Font>, FontDataCacheKeyHash, FontDataCacheKeyTraits> FontDataCache;
+typedef HashMap<FontPlatformData, Ref<Font>, FontDataCacheKeyHash, FontDataCacheKeyTraits> FontDataCache;
 
 static FontDataCache& cachedFonts()
 {
@@ -337,13 +337,13 @@ Ref<Font> FontCache::fontForPlatformData(const FontPlatformData& platformData)
     auto locker = holdLock(fontLock);
 #endif
     
-    auto addResult = cachedFonts().add(platformData, nullptr);
-    if (addResult.isNewEntry)
-        addResult.iterator->value = Font::create(platformData);
+    auto addResult = cachedFonts().ensure(platformData, [&] {
+        return Font::create(platformData);
+    });
 
     ASSERT(addResult.iterator->value->platformData() == platformData);
 
-    return *addResult.iterator->value;
+    return addResult.iterator->value.copyRef();
 }
 
 void FontCache::purgeInactiveFontDataIfNeeded()
@@ -375,12 +375,12 @@ void FontCache::purgeInactiveFontData(unsigned purgeCount)
 #endif
 
     while (purgeCount) {
-        Vector<RefPtr<Font>, 20> fontsToDelete;
-        for (auto font : cachedFonts().values()) {
+        Vector<Ref<Font>, 20> fontsToDelete;
+        for (auto& font : cachedFonts().values()) {
             LOG(Fonts, " trying to purge font %s (has one ref %d)", font->platformData().description().utf8().data(), font->hasOneRef());
             if (!font->hasOneRef())
                 continue;
-            fontsToDelete.append(WTFMove(font));
+            fontsToDelete.append(font.copyRef());
             if (!--purgeCount)
                 break;
         }