Title: [210778] trunk/Source/WebCore
Revision
210778
Author
mmaxfi...@apple.com
Date
2017-01-15 09:47:00 -0800 (Sun, 15 Jan 2017)

Log Message

[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):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (210777 => 210778)


--- trunk/Source/WebCore/ChangeLog	2017-01-15 10:48:04 UTC (rev 210777)
+++ trunk/Source/WebCore/ChangeLog	2017-01-15 17:47:00 UTC (rev 210778)
@@ -1,3 +1,36 @@
+2017-01-15  Myles C. Maxfield  <mmaxfi...@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  <akl...@apple.com>
 
         FrameView shouldn't keep dangling pointers into dead render trees.

Modified: trunk/Source/WebCore/platform/graphics/FontPlatformData.h (210777 => 210778)


--- trunk/Source/WebCore/platform/graphics/FontPlatformData.h	2017-01-15 10:48:04 UTC (rev 210777)
+++ trunk/Source/WebCore/platform/graphics/FontPlatformData.h	2017-01-15 17:47:00 UTC (rev 210778)
@@ -172,25 +172,7 @@
     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
     {

Modified: trunk/Source/WebCore/platform/graphics/cocoa/FontPlatformDataCocoa.mm (210777 => 210778)


--- trunk/Source/WebCore/platform/graphics/cocoa/FontPlatformDataCocoa.mm	2017-01-15 10:48:04 UTC (rev 210777)
+++ trunk/Source/WebCore/platform/graphics/cocoa/FontPlatformDataCocoa.mm	2017-01-15 17:47:00 UTC (rev 210778)
@@ -58,18 +58,19 @@
 #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 @@
 
     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;

Modified: trunk/Source/WebCore/platform/graphics/freetype/FontPlatformDataFreeType.cpp (210777 => 210778)


--- trunk/Source/WebCore/platform/graphics/freetype/FontPlatformDataFreeType.cpp	2017-01-15 10:48:04 UTC (rev 210777)
+++ trunk/Source/WebCore/platform/graphics/freetype/FontPlatformDataFreeType.cpp	2017-01-15 17:47:00 UTC (rev 210778)
@@ -280,6 +280,11 @@
     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.

Modified: trunk/Source/WebCore/platform/graphics/win/FontPlatformDataCGWin.cpp (210777 => 210778)


--- trunk/Source/WebCore/platform/graphics/win/FontPlatformDataCGWin.cpp	2017-01-15 10:48:04 UTC (rev 210777)
+++ trunk/Source/WebCore/platform/graphics/win/FontPlatformDataCGWin.cpp	2017-01-15 17:47:00 UTC (rev 210778)
@@ -129,6 +129,11 @@
 {
 }
 
+unsigned FontPlatformData::hash() const
+{
+    return m_font ? m_font->hash() : 0;
+}
+
 bool FontPlatformData::platformIsEqual(const FontPlatformData& other) const
 {
     return m_font == other.m_font

Modified: trunk/Source/WebCore/platform/graphics/win/FontPlatformDataCairoWin.cpp (210777 => 210778)


--- trunk/Source/WebCore/platform/graphics/win/FontPlatformDataCairoWin.cpp	2017-01-15 10:48:04 UTC (rev 210777)
+++ trunk/Source/WebCore/platform/graphics/win/FontPlatformDataCairoWin.cpp	2017-01-15 17:47:00 UTC (rev 210778)
@@ -85,6 +85,11 @@
     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

Modified: trunk/Source/WebCore/platform/graphics/win/FontPlatformDataDirect2D.cpp (210777 => 210778)


--- trunk/Source/WebCore/platform/graphics/win/FontPlatformDataDirect2D.cpp	2017-01-15 10:48:04 UTC (rev 210777)
+++ trunk/Source/WebCore/platform/graphics/win/FontPlatformDataDirect2D.cpp	2017-01-15 17:47:00 UTC (rev 210778)
@@ -104,6 +104,11 @@
     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
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to