[FreeType] Cache the zero-width space glyph in GlyphPage::fill()
authorzandobersek@gmail.com <zandobersek@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 16 Jan 2019 11:05:08 +0000 (11:05 +0000)
committerzandobersek@gmail.com <zandobersek@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 16 Jan 2019 11:05:08 +0000 (11:05 +0000)
https://bugs.webkit.org/show_bug.cgi?id=193485

Reviewed by Carlos Garcia Campos.

In FreeType's implementation of GlyphPage::fill(), we can cache the
zero-width space glyph upon first retrieval through the
FcFreeTypeCharIndex() entrypoint, avoiding any subsequent calls
for other ignorable characters.

* platform/graphics/freetype/GlyphPageTreeNodeFreeType.cpp:
(WebCore::GlyphPage::fill):

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

Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/freetype/GlyphPageTreeNodeFreeType.cpp

index c047f25..0585567 100644 (file)
@@ -1,3 +1,18 @@
+2019-01-16  Zan Dobersek  <zdobersek@igalia.com>
+
+        [FreeType] Cache the zero-width space glyph in GlyphPage::fill()
+        https://bugs.webkit.org/show_bug.cgi?id=193485
+
+        Reviewed by Carlos Garcia Campos.
+
+        In FreeType's implementation of GlyphPage::fill(), we can cache the
+        zero-width space glyph upon first retrieval through the
+        FcFreeTypeCharIndex() entrypoint, avoiding any subsequent calls
+        for other ignorable characters.
+
+        * platform/graphics/freetype/GlyphPageTreeNodeFreeType.cpp:
+        (WebCore::GlyphPage::fill):
+
 2019-01-16  Myles C. Maxfield  <mmaxfield@apple.com>
 
         [WHLSL] Add the high zombie finder
index dcdd26d..7c01975 100644 (file)
@@ -38,6 +38,7 @@
 #include <cairo-ft.h>
 #include <cairo.h>
 #include <fontconfig/fcfreetype.h>
+#include <wtf/Optional.h>
 
 namespace WebCore {
 
@@ -52,6 +53,14 @@ bool GlyphPage::fill(UChar* buffer, unsigned bufferLength)
     if (!face)
         return false;
 
+    WTF::Optional<Glyph> zeroWidthSpaceGlyphValue;
+    auto zeroWidthSpaceGlyph =
+        [&] {
+            if (!zeroWidthSpaceGlyphValue)
+                zeroWidthSpaceGlyphValue = FcFreeTypeCharIndex(face, zeroWidthSpace);
+            return *zeroWidthSpaceGlyphValue;
+        };
+
     bool haveGlyphs = false;
     UTF16UChar32Iterator iterator(buffer, bufferLength);
     for (unsigned i = 0; i < GlyphPage::size; i++) {
@@ -62,7 +71,7 @@ bool GlyphPage::fill(UChar* buffer, unsigned bufferLength)
         Glyph glyph = FcFreeTypeCharIndex(face, FontCascade::treatAsSpace(character) ? space : character);
         // If the font doesn't support a Default_Ignorable character, replace it with zero with space.
         if (!glyph && u_hasBinaryProperty(character, UCHAR_DEFAULT_IGNORABLE_CODE_POINT))
-            glyph = FcFreeTypeCharIndex(face, zeroWidthSpace);
+            glyph = zeroWidthSpaceGlyph();
 
         if (!glyph)
             setGlyphForIndex(i, 0);