Bug 1394551 - stylo: Dont unnecessarily construct gfxFontFeatureValueSet r?xidorn draft
authorNazım Can Altınova <canaltinova@gmail.com>
Wed, 30 Aug 2017 17:08:50 -0700
changeset 658835 0a6481f8455bdd1546a8df24b28f2f4016833d54
parent 658358 8e05298328da75f3056a9f1f9609938870d756a0
child 729759 dd7445f98aca8367df8009582bee8a0c9a2c9809
push id77883
push userbmo:canaltinova@gmail.com
push dateMon, 04 Sep 2017 22:58:03 +0000
reviewersxidorn
bugs1394551
milestone57.0a1
Bug 1394551 - stylo: Dont unnecessarily construct gfxFontFeatureValueSet r?xidorn If there is no font feature values inside document we should avoid creating unnecessary objects. MozReview-Commit-ID: HJKMzQvQAPR
layout/style/ServoBindingList.h
layout/style/ServoBindings.cpp
layout/style/ServoBindings.h
layout/style/ServoStyleSet.cpp
--- a/layout/style/ServoBindingList.h
+++ b/layout/style/ServoBindingList.h
@@ -101,19 +101,20 @@ SERVO_BINDING_FUNC(Servo_StyleSet_GetKey
                    const nsACString* property,
                    nsTimingFunctionBorrowed timing_function,
                    RawGeckoKeyframeListBorrowedMut keyframe_list)
 SERVO_BINDING_FUNC(Servo_StyleSet_GetFontFaceRules, void,
                    RawServoStyleSetBorrowed set,
                    RawGeckoFontFaceRuleListBorrowedMut list)
 SERVO_BINDING_FUNC(Servo_StyleSet_GetCounterStyleRule, nsCSSCounterStyleRule*,
                    RawServoStyleSetBorrowed set, nsIAtom* name)
-SERVO_BINDING_FUNC(Servo_StyleSet_BuildFontFeatureValueSet, bool,
-                   RawServoStyleSetBorrowed set,
-                   gfxFontFeatureValueSet* list)
+// This function may return nullptr or gfxFontFeatureValueSet with zero reference.
+SERVO_BINDING_FUNC(Servo_StyleSet_BuildFontFeatureValueSet,
+                   gfxFontFeatureValueSet*,
+                   RawServoStyleSetBorrowed set)
 SERVO_BINDING_FUNC(Servo_StyleSet_ResolveForDeclarations,
                    ServoStyleContextStrong,
                    RawServoStyleSetBorrowed set,
                    ServoStyleContextBorrowedOrNull parent_style,
                    RawServoDeclarationBlockBorrowed declarations)
 SERVO_BINDING_FUNC(Servo_StyleSet_AddSizeOfExcludingThis, void,
                    mozilla::MallocSizeOf malloc_size_of,
                    mozilla::ServoStyleSetSizes* sizes,
--- a/layout/style/ServoBindings.cpp
+++ b/layout/style/ServoBindings.cpp
@@ -1329,16 +1329,22 @@ Gecko_nsFont_InitSystem(nsFont* aDest, i
 }
 
 void
 Gecko_nsFont_Destroy(nsFont* aDest)
 {
   aDest->~nsFont();
 }
 
+gfxFontFeatureValueSet*
+Gecko_ConstructFontFeatureValueSet()
+{
+  return new gfxFontFeatureValueSet();
+}
+
 nsTArray<unsigned int>*
 Gecko_AppendFeatureValueHashEntry(gfxFontFeatureValueSet* aFontFeatureValues,
                                   nsIAtom* aFamily, uint32_t aAlternate, nsIAtom* aName)
 {
   MOZ_ASSERT(NS_IsMainThread());
   static_assert(sizeof(unsigned int) == sizeof(uint32_t),
                 "sizeof unsigned int and uint32_t must be the same");
   return aFontFeatureValues->AppendFeatureValueHashEntry(
--- a/layout/style/ServoBindings.h
+++ b/layout/style/ServoBindings.h
@@ -296,16 +296,18 @@ void Gecko_FontFamilyList_AppendNamed(Fo
 void Gecko_FontFamilyList_AppendGeneric(FontFamilyList* list, FontFamilyType familyType);
 void Gecko_CopyFontFamilyFrom(nsFont* dst, const nsFont* src);
 // will not run destructors on dst, give it uninitialized memory
 // font_id is LookAndFeel::FontID
 void Gecko_nsFont_InitSystem(nsFont* dst, int32_t font_id,
                              const nsStyleFont* font, RawGeckoPresContextBorrowed pres_context);
 void Gecko_nsFont_Destroy(nsFont* dst);
 
+// The gfxFontFeatureValueSet returned from this function has zero reference.
+gfxFontFeatureValueSet* Gecko_ConstructFontFeatureValueSet();
 nsTArray<unsigned int>* Gecko_AppendFeatureValueHashEntry(
   gfxFontFeatureValueSet* value_set, nsIAtom* family, uint32_t alternate, nsIAtom* name);
 void Gecko_nsFont_SetFontFeatureValuesLookup(nsFont* font,
                                              const RawGeckoPresContext* pres_context);
 void Gecko_nsFont_ResetFontFeatureValuesLookup(nsFont* font);
 
 // Font variant alternates
 void Gecko_ClearAlternateValues(nsFont* font, size_t length);
--- a/layout/style/ServoStyleSet.cpp
+++ b/layout/style/ServoStyleSet.cpp
@@ -1343,21 +1343,18 @@ ServoStyleSet::CounterStyleRuleForName(n
 {
   return Servo_StyleSet_GetCounterStyleRule(mRawSet.get(), aName);
 }
 
 already_AddRefed<gfxFontFeatureValueSet>
 ServoStyleSet::BuildFontFeatureValueSet()
 {
   UpdateStylistIfNeeded();
-  RefPtr<gfxFontFeatureValueSet> set = new gfxFontFeatureValueSet();
-  bool setHasAnyRules = Servo_StyleSet_BuildFontFeatureValueSet(mRawSet.get(), set.get());
-  if (!setHasAnyRules) {
-    return nullptr;
-  }
+  RefPtr<gfxFontFeatureValueSet> set =
+    Servo_StyleSet_BuildFontFeatureValueSet(mRawSet.get());
   return set.forget();
 }
 
 already_AddRefed<ServoStyleContext>
 ServoStyleSet::ResolveForDeclarations(
   const ServoStyleContext* aParentOrNull,
   RawServoDeclarationBlockBorrowed aDeclarations)
 {