Bug 1471584 - Micro-optimize text shaping by avoiding an unnecessary virtual method call. r=lsalzman
authorJonathan Kew <jkew@mozilla.com>
Wed, 27 Jun 2018 16:12:43 +0100
changeset 479040 1b9dcb1b80dd3f906ab4f59556afe32b71c51d12
parent 479039 0b885ee1e1b218957ceaee8ca70c236a86c83435
child 479041 14b77f98e81c7bfb5520e9ca38c6bc280dbf08fa
push id9719
push userffxbld-merge
push dateFri, 24 Aug 2018 17:49:46 +0000
treeherdermozilla-beta@719ec98fba77 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerslsalzman
bugs1471584
milestone63.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1471584 - Micro-optimize text shaping by avoiding an unnecessary virtual method call. r=lsalzman
gfx/thebes/gfxHarfBuzzShaper.cpp
--- a/gfx/thebes/gfxHarfBuzzShaper.cpp
+++ b/gfx/thebes/gfxHarfBuzzShaper.cpp
@@ -52,17 +52,17 @@ gfxHarfBuzzShaper::gfxHarfBuzzShaper(gfx
       mCmapTable(nullptr),
       mCmapFormat(-1),
       mSubtableOffset(0),
       mUVSTableOffset(0),
       mNumLongHMetrics(0),
       mNumLongVMetrics(0),
       mDefaultVOrg(-1.0),
       mUseFontGetGlyph(aFont->ProvidesGetGlyph()),
-      mUseFontGlyphWidths(false),
+      mUseFontGlyphWidths(aFont->ProvidesGlyphWidths()),
       mInitialized(false),
       mVerticalInitialized(false),
       mLoadedLocaGlyf(false),
       mLocaLongOffsets(false)
 {
 }
 
 gfxHarfBuzzShaper::~gfxHarfBuzzShaper()
@@ -374,23 +374,23 @@ gfxHarfBuzzShaper::GetGlyphVAdvance(hb_c
                         uint16_t(metrics->metrics[glyph].advanceWidth));
 }
 
 /* static */
 hb_position_t
 gfxHarfBuzzShaper::HBGetGlyphHAdvance(hb_font_t *font, void *font_data,
                                       hb_codepoint_t glyph, void *user_data)
 {
-    const gfxHarfBuzzShaper::FontCallbackData *fcd =
+    const gfxHarfBuzzShaper::FontCallbackData* fcd =
         static_cast<const gfxHarfBuzzShaper::FontCallbackData*>(font_data);
-    gfxFont *gfxfont = fcd->mShaper->GetFont();
-    if (gfxfont->ProvidesGlyphWidths()) {
-        return gfxfont->GetGlyphWidth(*fcd->mDrawTarget, glyph);
+    const gfxHarfBuzzShaper* shaper = fcd->mShaper;
+    if (shaper->mUseFontGlyphWidths) {
+        return shaper->GetFont()->GetGlyphWidth(*fcd->mDrawTarget, glyph);
     }
-    return fcd->mShaper->GetGlyphHAdvance(glyph);
+    return shaper->GetGlyphHAdvance(glyph);
 }
 
 /* static */
 hb_position_t
 gfxHarfBuzzShaper::HBGetGlyphVAdvance(hb_font_t *font, void *font_data,
                                       hb_codepoint_t glyph, void *user_data)
 {
     const gfxHarfBuzzShaper::FontCallbackData *fcd =
@@ -1206,18 +1206,16 @@ bool
 gfxHarfBuzzShaper::Initialize()
 {
     if (mInitialized) {
         return mHBFont != nullptr;
     }
     mInitialized = true;
     mCallbackData.mShaper = this;
 
-    mUseFontGlyphWidths = mFont->ProvidesGlyphWidths();
-
     if (!sHBFontFuncs) {
         // static function callback pointers, initialized by the first
         // harfbuzz shaper used
         sHBFontFuncs = hb_font_funcs_create();
         hb_font_funcs_set_nominal_glyph_func(sHBFontFuncs,
                                              HBGetNominalGlyph,
                                              nullptr, nullptr);
         hb_font_funcs_set_variation_glyph_func(sHBFontFuncs,