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
--- 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)
{