Apply std::unique_ptr to FooFont classes
authorgyuyoung.kim@samsung.com <gyuyoung.kim@samsung.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 18 Oct 2014 03:37:20 +0000 (03:37 +0000)
committergyuyoung.kim@samsung.com <gyuyoung.kim@samsung.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 18 Oct 2014 03:37:20 +0000 (03:37 +0000)
https://bugs.webkit.org/show_bug.cgi?id=137769

Reviewed by Andreas Kling.

As a step to use std::unique_ptr, this patch applies std::unique_ptr to Font classes.

No new tests, no behavior changes.

* platform/graphics/Font.cpp:
(WebCore::retrieveOrAddCachedFontGlyphs):
(WebCore::Font::createLayout):
* platform/graphics/SimpleFontData.cpp:
(WebCore::SimpleFontData::DerivedFontData::create):
* platform/graphics/SimpleFontData.h:
Remove create() factory function because public ctor and std::make_unique<> can replace it.
* platform/graphics/mac/ComplexTextController.cpp:
(WebCore::Font::createLayout):

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

Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/Font.cpp
Source/WebCore/platform/graphics/SimpleFontData.cpp
Source/WebCore/platform/graphics/SimpleFontData.h
Source/WebCore/platform/graphics/mac/ComplexTextController.cpp
Source/WebCore/platform/graphics/mac/SimpleFontDataMac.mm

index f2d302f..479c9fc 100644 (file)
@@ -1,5 +1,26 @@
 2014-10-17  Gyuyoung Kim  <gyuyoung.kim@samsung.com>
 
+        Apply std::unique_ptr to FooFont classes
+        https://bugs.webkit.org/show_bug.cgi?id=137769
+
+        Reviewed by Andreas Kling.
+
+        As a step to use std::unique_ptr, this patch applies std::unique_ptr to Font classes.
+
+        No new tests, no behavior changes.
+
+        * platform/graphics/Font.cpp:
+        (WebCore::retrieveOrAddCachedFontGlyphs):
+        (WebCore::Font::createLayout):
+        * platform/graphics/SimpleFontData.cpp:
+        (WebCore::SimpleFontData::DerivedFontData::create):
+        * platform/graphics/SimpleFontData.h:
+        Remove create() factory function because public ctor and std::make_unique<> can replace it.
+        * platform/graphics/mac/ComplexTextController.cpp:
+        (WebCore::Font::createLayout):
+
+2014-10-17  Gyuyoung Kim  <gyuyoung.kim@samsung.com>
+
         Use std::unique_ptr in WebCore/bindings
         https://bugs.webkit.org/show_bug.cgi?id=137808
 
index a5b4d12..39230c8 100644 (file)
@@ -220,7 +220,7 @@ public:
     Ref<FontGlyphs> glyphs;
 };
 
-typedef HashMap<unsigned, OwnPtr<FontGlyphsCacheEntry>, AlreadyHashed> FontGlyphsCache;
+typedef HashMap<unsigned, std::unique_ptr<FontGlyphsCacheEntry>, AlreadyHashed> FontGlyphsCache;
 
 static bool operator==(const FontGlyphsCacheKey& a, const FontGlyphsCacheKey& b)
 {
@@ -302,12 +302,12 @@ static PassRef<FontGlyphs> retrieveOrAddCachedFontGlyphs(const FontDescription&
     makeFontGlyphsCacheKey(key, fontDescription, fontSelector.get());
 
     unsigned hash = computeFontGlyphsCacheHash(key);
-    FontGlyphsCache::AddResult addResult = fontGlyphsCache().add(hash, PassOwnPtr<FontGlyphsCacheEntry>());
+    FontGlyphsCache::AddResult addResult = fontGlyphsCache().add(hash, std::unique_ptr<FontGlyphsCacheEntry>());
     if (!addResult.isNewEntry && addResult.iterator->value->key == key)
         return addResult.iterator->value->glyphs.get();
 
-    OwnPtr<FontGlyphsCacheEntry>& newEntry = addResult.iterator->value;
-    newEntry = adoptPtr(new FontGlyphsCacheEntry(WTF::move(key), FontGlyphs::create(fontSelector)));
+    std::unique_ptr<FontGlyphsCacheEntry>& newEntry = addResult.iterator->value;
+    newEntry = std::make_unique<FontGlyphsCacheEntry>(WTF::move(key), FontGlyphs::create(fontSelector));
     PassRef<FontGlyphs> glyphs = newEntry->glyphs.get();
 
     static const unsigned unreferencedPruneInterval = 50;
index 903357e..873e91c 100644 (file)
@@ -181,7 +181,7 @@ bool SimpleFontData::isSegmented() const
 PassRefPtr<SimpleFontData> SimpleFontData::verticalRightOrientationFontData() const
 {
     if (!m_derivedFontData)
-        m_derivedFontData = DerivedFontData::create(isCustomFont());
+        m_derivedFontData = std::make_unique<DerivedFontData>(isCustomFont());
     if (!m_derivedFontData->verticalRightOrientation) {
         FontPlatformData verticalRightPlatformData(m_platformData);
         verticalRightPlatformData.setOrientation(Horizontal);
@@ -193,7 +193,7 @@ PassRefPtr<SimpleFontData> SimpleFontData::verticalRightOrientationFontData() co
 PassRefPtr<SimpleFontData> SimpleFontData::uprightOrientationFontData() const
 {
     if (!m_derivedFontData)
-        m_derivedFontData = DerivedFontData::create(isCustomFont());
+        m_derivedFontData = std::make_unique<DerivedFontData>(isCustomFont());
     if (!m_derivedFontData->uprightOrientation)
         m_derivedFontData->uprightOrientation = create(m_platformData, isCustomFont(), false, true);
     return m_derivedFontData->uprightOrientation;
@@ -202,7 +202,7 @@ PassRefPtr<SimpleFontData> SimpleFontData::uprightOrientationFontData() const
 PassRefPtr<SimpleFontData> SimpleFontData::smallCapsFontData(const FontDescription& fontDescription) const
 {
     if (!m_derivedFontData)
-        m_derivedFontData = DerivedFontData::create(isCustomFont());
+        m_derivedFontData = std::make_unique<DerivedFontData>(isCustomFont());
     if (!m_derivedFontData->smallCaps)
         m_derivedFontData->smallCaps = createScaledFontData(fontDescription, smallCapsFontSizeMultiplier);
 
@@ -212,7 +212,7 @@ PassRefPtr<SimpleFontData> SimpleFontData::smallCapsFontData(const FontDescripti
 PassRefPtr<SimpleFontData> SimpleFontData::emphasisMarkFontData(const FontDescription& fontDescription) const
 {
     if (!m_derivedFontData)
-        m_derivedFontData = DerivedFontData::create(isCustomFont());
+        m_derivedFontData = std::make_unique<DerivedFontData>(isCustomFont());
     if (!m_derivedFontData->emphasisMark)
         m_derivedFontData->emphasisMark = createScaledFontData(fontDescription, emphasisMarkFontSizeMultiplier);
 
@@ -222,7 +222,7 @@ PassRefPtr<SimpleFontData> SimpleFontData::emphasisMarkFontData(const FontDescri
 PassRefPtr<SimpleFontData> SimpleFontData::brokenIdeographFontData() const
 {
     if (!m_derivedFontData)
-        m_derivedFontData = DerivedFontData::create(isCustomFont());
+        m_derivedFontData = std::make_unique<DerivedFontData>(isCustomFont());
     if (!m_derivedFontData->brokenIdeograph) {
         m_derivedFontData->brokenIdeograph = create(m_platformData, isCustomFont(), false);
         m_derivedFontData->brokenIdeograph->m_isBrokenIdeographFallback = true;
@@ -233,7 +233,7 @@ PassRefPtr<SimpleFontData> SimpleFontData::brokenIdeographFontData() const
 PassRefPtr<SimpleFontData> SimpleFontData::nonSyntheticItalicFontData() const
 {
     if (!m_derivedFontData)
-        m_derivedFontData = DerivedFontData::create(isCustomFont());
+        m_derivedFontData = std::make_unique<DerivedFontData>(isCustomFont());
     if (!m_derivedFontData->nonSyntheticItalic) {
         FontPlatformData nonSyntheticItalicFontPlatformData(m_platformData);
 #if PLATFORM(COCOA)
@@ -268,11 +268,6 @@ const OpenTypeMathData* SimpleFontData::mathData() const
     return m_mathData.get();
 }
 
-PassOwnPtr<SimpleFontData::DerivedFontData> SimpleFontData::DerivedFontData::create(bool forCustomFont)
-{
-    return adoptPtr(new DerivedFontData(forCustomFont));
-}
-
 SimpleFontData::DerivedFontData::~DerivedFontData()
 {
     if (!forCustomFont)
index 6b49d4c..e123451 100644 (file)
@@ -38,7 +38,6 @@
 #endif
 #include "TypesettingFeatures.h"
 #include <wtf/OwnPtr.h>
-#include <wtf/PassOwnPtr.h>
 #include <wtf/TypeCasts.h>
 #include <wtf/text/StringHash.h>
 
@@ -302,7 +301,10 @@ private:
     GlyphData m_missingGlyphData;
 
     struct DerivedFontData {
-        static PassOwnPtr<DerivedFontData> create(bool forCustomFont);
+        explicit DerivedFontData(bool custom)
+            : forCustomFont(custom)
+        {
+        }
         ~DerivedFontData();
 
         bool forCustomFont;
@@ -315,15 +317,9 @@ private:
 #if PLATFORM(COCOA)
         mutable RetainPtr<CFMutableDictionaryRef> compositeFontReferences;
 #endif
-
-    private:
-        DerivedFontData(bool custom)
-            : forCustomFont(custom)
-        {
-        }
     };
 
-    mutable OwnPtr<DerivedFontData> m_derivedFontData;
+    mutable std::unique_ptr<DerivedFontData> m_derivedFontData;
 
 #if USE(CG) || USE(CAIRO)
     float m_syntheticBoldOffset;
index 35ca736..5ebd43e 100644 (file)
@@ -52,7 +52,7 @@ public:
     TextLayout(RenderText* text, const Font& font, float xPos)
         : m_font(font)
         , m_run(constructTextRun(text, font, xPos))
-        , m_controller(adoptPtr(new ComplexTextController(&m_font, m_run, true)))
+        , m_controller(std::make_unique<ComplexTextController>(&m_font, m_run, true))
     {
     }
 
@@ -81,7 +81,7 @@ private:
     // ComplexTextController has only references to its Font and TextRun so they must be kept alive here.
     Font m_font;
     TextRun m_run;
-    OwnPtr<ComplexTextController> m_controller;
+    std::unique_ptr<ComplexTextController> m_controller;
 };
 
 PassOwnPtr<TextLayout> Font::createLayout(RenderText* text, float xPos, bool collapseWhiteSpace) const
index fbdc744..63873dc 100644 (file)
@@ -99,7 +99,7 @@ const SimpleFontData* SimpleFontData::getCompositeFontReferenceFontData(NSFont *
 {
     if (key && !CFEqual(adoptCF(CTFontCopyPostScriptName(CTFontRef(key))).get(), CFSTR("LastResort"))) {
         if (!m_derivedFontData)
-            m_derivedFontData = DerivedFontData::create(isCustomFont());
+            m_derivedFontData = std::make_unique<DerivedFontData>(isCustomFont());
         if (!m_derivedFontData->compositeFontReferences)
             m_derivedFontData->compositeFontReferences = adoptCF(CFDictionaryCreateMutable(kCFAllocatorDefault, 1, &kCFTypeDictionaryKeyCallBacks, NULL));
         else {