[Cocoa] Unify FontPlatformData's hashing and equality operators
authormmaxfield@apple.com <mmaxfield@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 15 Jan 2017 17:47:00 +0000 (17:47 +0000)
committermmaxfield@apple.com <mmaxfield@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 15 Jan 2017 17:47:00 +0000 (17:47 +0000)
https://bugs.webkit.org/show_bug.cgi?id=167061

Reviewed by Darin Adler.

On iOS, we were using CFEqual() and CFHash(), while on macOS
we were using pointer hashing and pointer equality. Instead,
we should be consistent about these operators.

Right now, FontPlatformData holds two internal CTFontRefs, and
switching to these higher-level CFEqual() and CFHash()
functions is required for eliminating one of these two
internal font objects.

No new tests because there is no behavior change.

* platform/graphics/FontPlatformData.h:
(WebCore::FontPlatformData::hash): Deleted.
* platform/graphics/cocoa/FontPlatformDataCocoa.mm:
(WebCore::FontPlatformData::hash):
(WebCore::FontPlatformData::platformIsEqual):
(WebCore::cascadeToLastResortAttributesDictionary):
* platform/graphics/freetype/FontPlatformDataFreeType.cpp:
(WebCore::FontPlatformData::hash):
* platform/graphics/win/FontPlatformDataCGWin.cpp:
(WebCore::FontPlatformData::hash):
* platform/graphics/win/FontPlatformDataCairoWin.cpp:
(WebCore::FontPlatformData::hash):
* platform/graphics/win/FontPlatformDataDirect2D.cpp:
(WebCore::FontPlatformData::hash):

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

Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/FontPlatformData.h
Source/WebCore/platform/graphics/cocoa/FontPlatformDataCocoa.mm
Source/WebCore/platform/graphics/freetype/FontPlatformDataFreeType.cpp
Source/WebCore/platform/graphics/win/FontPlatformDataCGWin.cpp
Source/WebCore/platform/graphics/win/FontPlatformDataCairoWin.cpp
Source/WebCore/platform/graphics/win/FontPlatformDataDirect2D.cpp

index d2027c6..75f0f48 100644 (file)
@@ -1,3 +1,36 @@
+2017-01-15  Myles C. Maxfield  <mmaxfield@apple.com>
+
+        [Cocoa] Unify FontPlatformData's hashing and equality operators
+        https://bugs.webkit.org/show_bug.cgi?id=167061
+
+        Reviewed by Darin Adler.
+
+        On iOS, we were using CFEqual() and CFHash(), while on macOS
+        we were using pointer hashing and pointer equality. Instead,
+        we should be consistent about these operators.
+
+        Right now, FontPlatformData holds two internal CTFontRefs, and
+        switching to these higher-level CFEqual() and CFHash()
+        functions is required for eliminating one of these two
+        internal font objects.
+
+        No new tests because there is no behavior change.
+
+        * platform/graphics/FontPlatformData.h:
+        (WebCore::FontPlatformData::hash): Deleted.
+        * platform/graphics/cocoa/FontPlatformDataCocoa.mm:
+        (WebCore::FontPlatformData::hash):
+        (WebCore::FontPlatformData::platformIsEqual):
+        (WebCore::cascadeToLastResortAttributesDictionary):
+        * platform/graphics/freetype/FontPlatformDataFreeType.cpp:
+        (WebCore::FontPlatformData::hash):
+        * platform/graphics/win/FontPlatformDataCGWin.cpp:
+        (WebCore::FontPlatformData::hash):
+        * platform/graphics/win/FontPlatformDataCairoWin.cpp:
+        (WebCore::FontPlatformData::hash):
+        * platform/graphics/win/FontPlatformDataDirect2D.cpp:
+        (WebCore::FontPlatformData::hash):
+
 2017-01-15  Andreas Kling  <akling@apple.com>
 
         FrameView shouldn't keep dangling pointers into dead render trees.
index ad382f4..b154b65 100644 (file)
@@ -172,25 +172,7 @@ public:
     FcFontSet* fallbacks() const;
 #endif
 
-    unsigned hash() const
-    {
-#if USE(CAIRO)
-        return PtrHash<cairo_scaled_font_t*>::hash(m_scaledFont.get());
-#elif PLATFORM(WIN)
-        return m_font ? m_font->hash() : 0;
-#elif PLATFORM(COCOA)
-        uintptr_t flags = static_cast<uintptr_t>(m_isHashTableDeletedValue << 5 | m_textRenderingMode << 3 | m_orientation << 2 | m_syntheticBold << 1 | m_syntheticOblique);
-#if USE(APPKIT)
-        uintptr_t fontHash = (uintptr_t)m_font.get();
-#else
-        uintptr_t fontHash = reinterpret_cast<uintptr_t>(CFHash(m_font.get()));
-#endif
-        uintptr_t hashCodes[3] = { fontHash, m_widthVariant, flags };
-        return StringHasher::hashMemory<sizeof(hashCodes)>(hashCodes);
-#else
-#error "Unsupported configuration"
-#endif
-    }
+    unsigned hash() const;
 
     bool operator==(const FontPlatformData& other) const
     {
index e22e326..0da13fa 100644 (file)
@@ -58,18 +58,19 @@ FontPlatformData::FontPlatformData(CTFontRef font, float size, bool syntheticBol
 #endif
 }
 
+unsigned FontPlatformData::hash() const
+{
+    uintptr_t flags = static_cast<uintptr_t>(m_isHashTableDeletedValue << 5 | m_textRenderingMode << 3 | m_orientation << 2 | m_syntheticBold << 1 | m_syntheticOblique);
+    uintptr_t fontHash = reinterpret_cast<uintptr_t>(CFHash(m_font.get()));
+    uintptr_t hashCodes[3] = { fontHash, m_widthVariant, flags };
+    return StringHasher::hashMemory<sizeof(hashCodes)>(hashCodes);
+}
+
 bool FontPlatformData::platformIsEqual(const FontPlatformData& other) const
 {
-    bool result = false;
-    if (m_font || other.m_font) {
-#if PLATFORM(IOS)
-        result = m_font && other.m_font && CFEqual(m_font.get(), other.m_font.get());
-#else
-        result = m_font == other.m_font;
-#endif
-        return result;
-    }
-    return true;
+    if (!m_font || !other.m_font)
+        return m_font == other.m_font;
+    return CFEqual(m_font.get(), other.m_font.get());
 }
 
 CTFontRef FontPlatformData::registeredFont() const
@@ -109,11 +110,11 @@ static CFDictionaryRef cascadeToLastResortAttributesDictionary()
 
     RetainPtr<CTFontDescriptorRef> lastResort = adoptCF(CTFontDescriptorCreateWithNameAndSize(CFSTR("LastResort"), 0));
 
-    const void* descriptors[] = { lastResort.get() };
+    CFTypeRef descriptors[] = { lastResort.get() };
     RetainPtr<CFArrayRef> array = adoptCF(CFArrayCreate(kCFAllocatorDefault, descriptors, WTF_ARRAY_LENGTH(descriptors), &kCFTypeArrayCallBacks));
 
-    const void* keys[] = { kCTFontCascadeListAttribute };
-    const void* values[] = { array.get() };
+    CFTypeRef keys[] = { kCTFontCascadeListAttribute };
+    CFTypeRef values[] = { array.get() };
     attributes = CFDictionaryCreate(kCFAllocatorDefault, keys, values, WTF_ARRAY_LENGTH(keys), &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
 
     return attributes;
index 84e1ba1..b8ec73c 100644 (file)
@@ -280,6 +280,11 @@ bool FontPlatformData::isFixedPitch() const
     return m_fixedWidth;
 }
 
+unsigned FontPlatformData::hash() const
+{
+    return PtrHash<cairo_scaled_font_t*>::hash(m_scaledFont.get());
+}
+
 bool FontPlatformData::platformIsEqual(const FontPlatformData& other) const
 {
     // FcPatternEqual does not support null pointers as arguments.
index 8920071..a845341 100644 (file)
@@ -129,6 +129,11 @@ FontPlatformData::FontPlatformData(GDIObject<HFONT> hfont, CGFontRef font, float
 {
 }
 
+unsigned FontPlatformData::hash() const
+{
+    return m_font ? m_font->hash() : 0;
+}
+
 bool FontPlatformData::platformIsEqual(const FontPlatformData& other) const
 {
     return m_font == other.m_font
index f888994..e63a122 100644 (file)
@@ -85,6 +85,11 @@ FontPlatformData::FontPlatformData(GDIObject<HFONT> font, cairo_font_face_t* fon
     cairo_font_options_destroy(options);
 }
 
+unsigned FontPlatformData::hash() const
+{
+    return PtrHash<cairo_scaled_font_t*>::hash(m_scaledFont.get());
+}
+
 bool FontPlatformData::platformIsEqual(const FontPlatformData& other) const
 {
     return m_font == other.m_font
index d464dca..e0f424d 100644 (file)
@@ -104,6 +104,11 @@ static bool fontsAreEqual(IDWriteFont* a, IDWriteFont* b)
     return true;
 }
 
+unsigned FontPlatformData::hash() const
+{
+    return m_font ? m_font->hash() : 0;
+}
+
 bool FontPlatformData::platformIsEqual(const FontPlatformData& other) const
 {
     return m_font == other.m_font