Global FontPlatformData cache should use OwnPtr.
authorakling@apple.com <akling@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 4 Apr 2013 16:37:08 +0000 (16:37 +0000)
committerakling@apple.com <akling@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 4 Apr 2013 16:37:08 +0000 (16:37 +0000)
<http://webkit.org/b/111939>

Reviewed by Anders Carlsson.

Let the global FontPlatformData use OwnPtr instead of raw pointers + deleteAllValues().

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

    Tweaked code for OwnPtr. Also made getCachedFontPlatformData() do one hash lookup
    instead of two.

* platform/graphics/FontCache.h:
* platform/graphics/blackberry/FontCacheBlackBerry.cpp:
(WebCore::FontCache::createFontPlatformData):
* platform/graphics/chromium/FontCacheAndroid.cpp:
(WebCore::FontCache::createFontPlatformData):
* platform/graphics/freetype/FontCacheFreeType.cpp:
(WebCore::FontCache::createFontPlatformData):
* platform/graphics/mac/FontCacheMac.mm:
(WebCore::FontCache::createFontPlatformData):
* platform/graphics/qt/FontCacheQt.cpp:
(WebCore::FontCache::createFontPlatformData):
* platform/graphics/skia/FontCacheSkia.cpp:
(WebCore::FontCache::createFontPlatformData):
* platform/graphics/win/FontCacheWin.cpp:
(WebCore::FontCache::createFontPlatformData):
* platform/graphics/wince/FontCacheWinCE.cpp:
(WebCore::FontCache::createFontPlatformData):
* platform/graphics/wx/FontCacheWx.cpp:
(WebCore::FontCache::createFontPlatformData):

    FontCache::createFontPlatformData() now returns a PassOwnPtr.

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

12 files changed:
Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/FontCache.cpp
Source/WebCore/platform/graphics/FontCache.h
Source/WebCore/platform/graphics/blackberry/FontCacheBlackBerry.cpp
Source/WebCore/platform/graphics/chromium/FontCacheAndroid.cpp
Source/WebCore/platform/graphics/freetype/FontCacheFreeType.cpp
Source/WebCore/platform/graphics/mac/FontCacheMac.mm
Source/WebCore/platform/graphics/qt/FontCacheQt.cpp
Source/WebCore/platform/graphics/skia/FontCacheSkia.cpp
Source/WebCore/platform/graphics/win/FontCacheWin.cpp
Source/WebCore/platform/graphics/wince/FontCacheWinCE.cpp
Source/WebCore/platform/graphics/wx/FontCacheWx.cpp

index 69ec0dd..b91ab9b 100644 (file)
@@ -1,5 +1,44 @@
 2013-04-04  Andreas Kling  <akling@apple.com>
 
+        Global FontPlatformData cache should use OwnPtr.
+        <http://webkit.org/b/111939>
+
+        Reviewed by Anders Carlsson.
+
+        Let the global FontPlatformData use OwnPtr instead of raw pointers + deleteAllValues().
+
+        * platform/graphics/FontCache.cpp:
+        (WebCore::FontCache::getCachedFontPlatformData):
+        (WebCore::FontCache::purgeInactiveFontData):
+        (WebCore::FontCache::invalidate):
+
+            Tweaked code for OwnPtr. Also made getCachedFontPlatformData() do one hash lookup
+            instead of two.
+
+        * platform/graphics/FontCache.h:
+        * platform/graphics/blackberry/FontCacheBlackBerry.cpp:
+        (WebCore::FontCache::createFontPlatformData):
+        * platform/graphics/chromium/FontCacheAndroid.cpp:
+        (WebCore::FontCache::createFontPlatformData):
+        * platform/graphics/freetype/FontCacheFreeType.cpp:
+        (WebCore::FontCache::createFontPlatformData):
+        * platform/graphics/mac/FontCacheMac.mm:
+        (WebCore::FontCache::createFontPlatformData):
+        * platform/graphics/qt/FontCacheQt.cpp:
+        (WebCore::FontCache::createFontPlatformData):
+        * platform/graphics/skia/FontCacheSkia.cpp:
+        (WebCore::FontCache::createFontPlatformData):
+        * platform/graphics/win/FontCacheWin.cpp:
+        (WebCore::FontCache::createFontPlatformData):
+        * platform/graphics/wince/FontCacheWinCE.cpp:
+        (WebCore::FontCache::createFontPlatformData):
+        * platform/graphics/wx/FontCacheWx.cpp:
+        (WebCore::FontCache::createFontPlatformData):
+
+            FontCache::createFontPlatformData() now returns a PassOwnPtr.
+
+2013-04-04  Andreas Kling  <akling@apple.com>
+
         Render images with low-quality scaling while FrameView is being resized.
         <http://webkit.org/b/113764>
         <rdar://problem/13555154>
index 0d4e84a..6cf8389 100644 (file)
@@ -125,7 +125,7 @@ struct FontPlatformDataCacheKeyHash {
 
 struct FontPlatformDataCacheKeyTraits : WTF::SimpleClassHashTraits<FontPlatformDataCacheKey> { };
 
-typedef HashMap<FontPlatformDataCacheKey, FontPlatformData*, FontPlatformDataCacheKeyHash, FontPlatformDataCacheKeyTraits> FontPlatformDataCache;
+typedef HashMap<FontPlatformDataCacheKey, OwnPtr<FontPlatformData>, FontPlatformDataCacheKeyHash, FontPlatformDataCacheKeyTraits> FontPlatformDataCache;
 
 static FontPlatformDataCache* gFontPlatformDataCache = 0;
 
@@ -200,29 +200,24 @@ FontPlatformData* FontCache::getCachedFontPlatformData(const FontDescription& fo
     FontPlatformDataCacheKey key(familyName, fontDescription.computedPixelSize(), fontDescription.weight(), fontDescription.italic(),
                                  fontDescription.usePrinterFont(), fontDescription.renderingMode(), fontDescription.orientation(),
                                  fontDescription.widthVariant());
-    FontPlatformData* result = 0;
-    bool foundResult;
-    FontPlatformDataCache::iterator it = gFontPlatformDataCache->find(key);
-    if (it == gFontPlatformDataCache->end()) {
-        result = createFontPlatformData(fontDescription, familyName);
-        gFontPlatformDataCache->set(key, result);
-        foundResult = result;
-    } else {
-        result = it->value;
-        foundResult = true;
-    }
 
-    if (!foundResult && !checkingAlternateName) {
-        // We were unable to find a font.  We have a small set of fonts that we alias to other names, 
-        // e.g., Arial/Helvetica, Courier/Courier New, etc.  Try looking up the font under the aliased name.
-        const AtomicString& alternateName = alternateFamilyName(familyName);
-        if (!alternateName.isEmpty())
-            result = getCachedFontPlatformData(fontDescription, alternateName, true);
-        if (result)
-            gFontPlatformDataCache->set(key, new FontPlatformData(*result)); // Cache the result under the old name.
+    FontPlatformDataCache::AddResult result = gFontPlatformDataCache->add(key, nullptr);
+    if (result.isNewEntry) {
+        result.iterator->value = createFontPlatformData(fontDescription, familyName);
+
+        if (!result.iterator->value && !checkingAlternateName) {
+            // We were unable to find a font.  We have a small set of fonts that we alias to other names,
+            // e.g., Arial/Helvetica, Courier/Courier New, etc.  Try looking up the font under the aliased name.
+            const AtomicString& alternateName = alternateFamilyName(familyName);
+            if (!alternateName.isEmpty()) {
+                FontPlatformData* fontPlatformDataForAlternateName = getCachedFontPlatformData(fontDescription, alternateName, true);
+                if (fontPlatformDataForAlternateName)
+                    result.iterator->value = adoptPtr(new FontPlatformData(*fontPlatformDataForAlternateName));
+            }
+        }
     }
 
-    return result;
+    return result.iterator->value.get();
 }
 
 #if ENABLE(OPENTYPE_VERTICAL)
@@ -411,7 +406,7 @@ void FontCache::purgeInactiveFontData(int count)
         
         size_t keysToRemoveCount = keysToRemove.size();
         for (size_t i = 0; i < keysToRemoveCount; ++i)
-            delete gFontPlatformDataCache->take(keysToRemove[i]);
+            gFontPlatformDataCache->remove(keysToRemove[i]);
     }
 
 #if ENABLE(OPENTYPE_VERTICAL)
@@ -536,11 +531,8 @@ void FontCache::invalidate()
         return;
     }
 
-    if (gFontPlatformDataCache) {
-        deleteAllValues(*gFontPlatformDataCache);
-        delete gFontPlatformDataCache;
-        gFontPlatformDataCache = new FontPlatformDataCache;
-    }
+    if (gFontPlatformDataCache)
+        gFontPlatformDataCache->clear();
 
     gGeneration++;
 
index 20f0f83..3d4b47b 100644 (file)
@@ -150,7 +150,7 @@ private:
 
     // These methods are implemented by each platform.
     PassRefPtr<SimpleFontData> getSimilarFontPlatformData(const Font&);
-    FontPlatformData* createFontPlatformData(const FontDescription&, const AtomicString& family);
+    PassOwnPtr<FontPlatformData> createFontPlatformData(const FontDescription&, const AtomicString& family);
 
     PassRefPtr<SimpleFontData> getCachedFontData(const FontPlatformData*, ShouldRetain = Retain);
 
index aafcefe..7b6ca70 100644 (file)
@@ -147,7 +147,7 @@ PassRefPtr<SimpleFontData> FontCache::getFontDataForCharacters(const Font& font,
     FontCache::SimpleFontFamily family;
     FontCache::getFontFamilyForCharacters(characters, length, locale.getLanguage(), font.fontDescription(), &family);
     if (family.name.isEmpty())
-        return 0;
+        return nullptr;
 
     AtomicString atomicFamily(family.name);
     // Changes weight and/or italic of given FontDescription depends on
@@ -171,7 +171,7 @@ PassRefPtr<SimpleFontData> FontCache::getFontDataForCharacters(const Font& font,
 
     FontPlatformData* substitutePlatformData = getCachedFontPlatformData(description, atomicFamily, DoNotRetain);
     if (!substitutePlatformData)
-        return 0;
+        return nullptr;
     FontPlatformData platformData = FontPlatformData(*substitutePlatformData);
     platformData.setFakeBold(shouldSetFakeBold);
     platformData.setFakeItalic(shouldSetFakeItalic);
@@ -269,7 +269,7 @@ int fontWeightToFontconfigWeight(FontWeight weight)
     }
 }
 
-FontPlatformData* FontCache::createFontPlatformData(const FontDescription& fontDescription, const AtomicString& family)
+PassOwnPtr<FontPlatformData> FontCache::createFontPlatformData(const FontDescription& fontDescription, const AtomicString& family)
 {
     // The CSS font matching algorithm (http://www.w3.org/TR/css3-fonts/#font-matching-algorithm)
     // says that we must find an exact match for font family, slant (italic or oblique can be used)
@@ -277,15 +277,15 @@ FontPlatformData* FontCache::createFontPlatformData(const FontDescription& fontD
     FcPattern* pattern = FcPatternCreate();
     String familyNameString(getFamilyNameStringFromFontDescriptionAndFamily(fontDescription, family));
     if (!FcPatternAddString(pattern, FC_FAMILY, reinterpret_cast<const FcChar8*>(familyNameString.utf8().data())))
-        return 0;
+        return nullptr;
 
     bool italic = fontDescription.italic();
     if (!FcPatternAddInteger(pattern, FC_SLANT, italic ? FC_SLANT_ITALIC : FC_SLANT_ROMAN))
-        return 0;
+        return nullptr;
     if (!FcPatternAddInteger(pattern, FC_WEIGHT, fontWeightToFontconfigWeight(fontDescription.weight())))
-        return 0;
+        return nullptr;
     if (!FcPatternAddDouble(pattern, FC_PIXEL_SIZE, fontDescription.computedPixelSize()))
-        return 0;
+        return nullptr;
 
     // The strategy is originally from Skia (src/ports/SkFontHost_fontconfig.cpp):
 
@@ -303,7 +303,7 @@ FontPlatformData* FontCache::createFontPlatformData(const FontDescription& fontD
     FcPattern* resultPattern = FcFontMatch(0, pattern, &fontConfigResult);
     FcPatternDestroy(pattern);
     if (!resultPattern) // No match.
-        return 0;
+        return nullptr;
 
     FcChar8* fontConfigFamilyNameAfterMatching;
     FcPatternGetString(resultPattern, FC_FAMILY, 0, &fontConfigFamilyNameAfterMatching);
@@ -316,7 +316,7 @@ FontPlatformData* FontCache::createFontPlatformData(const FontDescription& fontD
         && !(equalIgnoringCase(familyNameString, "sans") || equalIgnoringCase(familyNameString, "sans-serif")
             || equalIgnoringCase(familyNameString, "serif") || equalIgnoringCase(familyNameString, "monospace")
             || equalIgnoringCase(familyNameString, "fantasy") || equalIgnoringCase(familyNameString, "cursive")))
-        return 0;
+        return nullptr;
 
     int fontWeight;
     FcPatternGetInteger(resultPattern, FC_WEIGHT, 0, &fontWeight);
@@ -335,10 +335,10 @@ FontPlatformData* FontCache::createFontPlatformData(const FontDescription& fontD
     memset(name, 0, MAX_FONT_NAME_LEN+1);
     // fprintf(stderr, "FS_load_font %s: ", fontFileName);
     if (FS_load_font(BlackBerry::Platform::Graphics::getIType(), reinterpret_cast<FILECHAR*>(fontFileName), 0, 0, MAX_FONT_NAME_LEN, name) != SUCCESS)
-        return 0;
+        return nullptr;
     // fprintf(stderr, " %s\n", name);
 
-    return new FontPlatformData(name, fontDescription.computedSize(), shouldFakeBold, shouldFakeItalic, fontDescription.orientation());
+    return adoptPtr(new FontPlatformData(name, fontDescription.computedSize(), shouldFakeBold, shouldFakeItalic, fontDescription.orientation()));
 }
 
 } // namespace WebCore
index 3f53ddf..0bd71da 100644 (file)
@@ -149,7 +149,7 @@ void FontCache::getTraitsInFamily(const AtomicString& familyName, Vector<unsigne
     notImplemented();
 }
 
-FontPlatformData* FontCache::createFontPlatformData(const FontDescription& fontDescription, const AtomicString& family)
+PassOwnPtr<FontPlatformData> FontCache::createFontPlatformData(const FontDescription& fontDescription, const AtomicString& family)
 {
     const char* name = 0;
     CString nameString; // Keeps name valid within scope of this function in case that name is from a family.
@@ -207,7 +207,7 @@ FontPlatformData* FontCache::createFontPlatformData(const FontDescription& fontD
     }
 
     SkSafeUnref(typeface);
-    return result;
+    return adoptPtr(result);
 }
 
 } // namespace WebCore
index dbad571..3e90bb2 100644 (file)
@@ -169,7 +169,7 @@ int fontWeightToFontconfigWeight(FontWeight weight)
     }
 }
 
-FontPlatformData* FontCache::createFontPlatformData(const FontDescription& fontDescription, const AtomicString& family)
+PassOwnPtr<FontPlatformData> FontCache::createFontPlatformData(const FontDescription& fontDescription, const AtomicString& family)
 {
     // The CSS font matching algorithm (http://www.w3.org/TR/css3-fonts/#font-matching-algorithm)
     // says that we must find an exact match for font family, slant (italic or oblique can be used)
@@ -177,15 +177,15 @@ FontPlatformData* FontCache::createFontPlatformData(const FontDescription& fontD
     RefPtr<FcPattern> pattern = adoptRef(FcPatternCreate());
     String familyNameString(getFamilyNameStringFromFontDescriptionAndFamily(fontDescription, family));
     if (!FcPatternAddString(pattern.get(), FC_FAMILY, reinterpret_cast<const FcChar8*>(familyNameString.utf8().data())))
-        return 0;
+        return nullptr;
 
     bool italic = fontDescription.italic();
     if (!FcPatternAddInteger(pattern.get(), FC_SLANT, italic ? FC_SLANT_ITALIC : FC_SLANT_ROMAN))
-        return 0;
+        return nullptr;
     if (!FcPatternAddInteger(pattern.get(), FC_WEIGHT, fontWeightToFontconfigWeight(fontDescription.weight())))
-        return 0;
+        return nullptr;
     if (!FcPatternAddDouble(pattern.get(), FC_PIXEL_SIZE, fontDescription.computedPixelSize()))
-        return 0;
+        return nullptr;
 
     // The strategy is originally from Skia (src/ports/SkFontHost_fontconfig.cpp):
 
@@ -202,7 +202,7 @@ FontPlatformData* FontCache::createFontPlatformData(const FontDescription& fontD
     FcResult fontConfigResult;
     RefPtr<FcPattern> resultPattern = adoptRef(FcFontMatch(0, pattern.get(), &fontConfigResult));
     if (!resultPattern) // No match.
-        return 0;
+        return nullptr;
 
     FcChar8* fontConfigFamilyNameAfterMatching;
     FcPatternGetString(resultPattern.get(), FC_FAMILY, 0, &fontConfigFamilyNameAfterMatching);
@@ -215,18 +215,16 @@ FontPlatformData* FontCache::createFontPlatformData(const FontDescription& fontD
         && !(equalIgnoringCase(familyNameString, "sans") || equalIgnoringCase(familyNameString, "sans-serif")
           || equalIgnoringCase(familyNameString, "serif") || equalIgnoringCase(familyNameString, "monospace")
           || equalIgnoringCase(familyNameString, "fantasy") || equalIgnoringCase(familyNameString, "cursive")))
-        return 0;
+        return nullptr;
 
     // Verify that this font has an encoding compatible with Fontconfig. Fontconfig currently
     // supports three encodings in FcFreeTypeCharIndex: Unicode, Symbol and AppleRoman.
     // If this font doesn't have one of these three encodings, don't select it.
-    FontPlatformData* platformData = new FontPlatformData(resultPattern.get(), fontDescription);
-    if (!platformData->hasCompatibleCharmap()) {
-        delete platformData;
-        return 0;
-    }
+    OwnPtr<FontPlatformData> platformData = adoptPtr(new FontPlatformData(resultPattern.get(), fontDescription));
+    if (!platformData->hasCompatibleCharmap())
+        return nullptr;
 
-    return platformData;
+    return platformData.release();
 }
 
 }
index 517181a..d1cc50d 100644 (file)
@@ -216,7 +216,7 @@ void FontCache::getTraitsInFamily(const AtomicString& familyName, Vector<unsigne
     [WebFontCache getTraits:traitsMasks inFamily:familyName];
 }
 
-FontPlatformData* FontCache::createFontPlatformData(const FontDescription& fontDescription, const AtomicString& family)
+PassOwnPtr<FontPlatformData> FontCache::createFontPlatformData(const FontDescription& fontDescription, const AtomicString& family)
 {
     NSFontTraitMask traits = fontDescription.italic() ? NSFontItalicTrait : 0;
     NSInteger weight = toAppKitFontWeight(fontDescription.weight());
@@ -224,7 +224,7 @@ FontPlatformData* FontCache::createFontPlatformData(const FontDescription& fontD
 
     NSFont *nsFont = [WebFontCache fontWithFamily:family traits:traits weight:weight size:size];
     if (!nsFont)
-        return 0;
+        return nullptr;
 
     NSFontManager *fontManager = [NSFontManager sharedFontManager];
     NSFontTraitMask actualTraits = 0;
@@ -240,8 +240,8 @@ FontPlatformData* FontCache::createFontPlatformData(const FontDescription& fontD
     // In that case, we don't want to use the platformData.
     OwnPtr<FontPlatformData> platformData = adoptPtr(new FontPlatformData(platformFont, size, fontDescription.usePrinterFont(), syntheticBold, syntheticOblique, fontDescription.orientation(), fontDescription.widthVariant()));
     if (!platformData->font())
-        return 0;
-    return platformData.leakPtr();
+        return nullptr;
+    return platformData.release();
 }
 
 } // namespace WebCore
index 6d1ee72..5049b81 100644 (file)
@@ -88,12 +88,12 @@ void FontCache::getTraitsInFamily(const AtomicString&, Vector<unsigned>&)
 {
 }
 
-FontPlatformData* FontCache::createFontPlatformData(const FontDescription& fontDescription, const AtomicString& familyName)
+PassOwnPtr<FontPlatformData> FontCache::createFontPlatformData(const FontDescription& fontDescription, const AtomicString& familyName)
 {
     QFontDatabase db;
     if (!db.hasFamily(familyName))
-        return 0;
-    return new FontPlatformData(fontDescription, familyName);
+        return nullptr;
+    return adoptPtr(new FontPlatformData(fontDescription, familyName));
 }
 
 } // namespace WebCore
index d2f088e..a45839a 100644 (file)
@@ -129,8 +129,7 @@ void FontCache::getTraitsInFamily(const AtomicString& familyName,
     notImplemented();
 }
 
-FontPlatformData* FontCache::createFontPlatformData(const FontDescription& fontDescription,
-                                                    const AtomicString& family)
+PassOwnPtr<FontPlatformData> FontCache::createFontPlatformData(const FontDescription& fontDescription, const AtomicString& family)
 {
     const char* name = 0;
     CString s;
@@ -172,7 +171,7 @@ FontPlatformData* FontCache::createFontPlatformData(const FontDescription& fontD
 
     SkTypeface* tf = SkTypeface::CreateFromName(name, static_cast<SkTypeface::Style>(style));
     if (!tf)
-        return 0;
+        return nullptr;
 
     FontPlatformData* result =
         new FontPlatformData(tf,
@@ -182,7 +181,7 @@ FontPlatformData* FontCache::createFontPlatformData(const FontDescription& fontD
                              (style & SkTypeface::kItalic) && !tf->isItalic(),
                              fontDescription.orientation());
     tf->unref();
-    return result;
+    return adoptPtr(result);
 }
 
 } // namespace WebCore
index ee55e1d..1e5ae1c 100644 (file)
@@ -545,7 +545,7 @@ void FontCache::getTraitsInFamily(const AtomicString& familyName, Vector<unsigne
     copyToVector(procData.m_traitsMasks, traitsMasks);
 }
 
-FontPlatformData* FontCache::createFontPlatformData(const FontDescription& fontDescription, const AtomicString& family)
+PassOwnPtr<FontPlatformData> FontCache::createFontPlatformData(const FontDescription& fontDescription, const AtomicString& family)
 {
     bool isLucidaGrande = false;
     static AtomicString lucidaStr("Lucida Grande");
@@ -563,7 +563,7 @@ FontPlatformData* FontCache::createFontPlatformData(const FontDescription& fontD
                                 fontDescription.computedPixelSize() * (useGDI ? 1 : 32), useGDI);
 
     if (!hfont)
-        return 0;
+        return nullptr;
 
     if (isLucidaGrande)
         useGDI = false; // Never use GDI for Lucida Grande.
@@ -588,10 +588,10 @@ FontPlatformData* FontCache::createFontPlatformData(const FontDescription& fontD
         // font.
         delete result;
         DeleteObject(hfont);
-        return 0;
+        return nullptr;
     }        
 
-    return result;
+    return adoptPtr(result);
 }
 
 }
index 9ab91a1..7b8020d 100644 (file)
@@ -312,10 +312,9 @@ PassRefPtr<SimpleFontData> FontCache::getLastResortFallbackFont(const FontDescri
     return getCachedFontData(fontDesc, FontPlatformData::defaultFontFamily(), false, shouldRetain);
 }
 
-FontPlatformData* FontCache::createFontPlatformData(const FontDescription& fontDescription, const AtomicString& family)
+PassOwnPtr<FontPlatformData> FontCache::createFontPlatformData(const FontDescription& fontDescription, const AtomicString& family)
 {
-    FontPlatformData* result = new FontPlatformData(fontDescription, family);
-    return result;
+    return adoptPtr(new FontPlatformData(fontDescription, family));
 }
 
 void FontCache::getTraitsInFamily(const AtomicString& familyName, Vector<unsigned>& traitsMasks)
index 5e90e05..a4af5b2 100644 (file)
@@ -97,14 +97,14 @@ PassRefPtr<SimpleFontData> FontCache::getLastResortFallbackFont(const FontDescri
     return fallback.release();
 }
 
-FontPlatformData* FontCache::createFontPlatformData(const FontDescription& fontDescription, const AtomicString& family)
+PassOwnPtr<FontPlatformData> FontCache::createFontPlatformData(const FontDescription& fontDescription, const AtomicString& family)
 {
     // wx will ALWAYS create a valid font, even if the font family we're looking for is not available.
     // So we check to make sure the font is the one we're looking for before creating the font.
     if (!wxFontEnumerator::IsValidFacename(family.string()))
-        return 0;
+        return nullptr;
 
-    return new FontPlatformData(fontDescription,family);
+    return adoptPtr(new FontPlatformData(fontDescription, family));
 }
 
 void FontCache::getTraitsInFamily(const AtomicString& familyName, Vector<unsigned>& traitsMasks)