Skip to content
Permalink
Browse files

Don't unnecessarily construct gfxFontFeatureValueSet

If there is no font feature values inside document we should avoid creating
unnecessary objects.
  • Loading branch information
canova committed Sep 4, 2017
1 parent 9b63fed commit dd8af182c10a434d9adbd848216560c85f05824e
Showing with 18 additions and 11 deletions.
  1. +6 −4 components/style/gecko/generated/bindings.rs
  2. +12 −7 ports/geckolib/glue.rs
@@ -913,6 +913,10 @@ extern "C" {
extern "C" {
pub fn Gecko_nsFont_Destroy(dst: *mut nsFont);
}
extern "C" {
pub fn Gecko_ConstructFontFeatureValueSet()
-> *mut gfxFontFeatureValueSet;
}
extern "C" {
pub fn Gecko_AppendFeatureValueHashEntry(value_set:
*mut gfxFontFeatureValueSet,
@@ -2047,10 +2051,8 @@ extern "C" {
}
extern "C" {
pub fn Servo_StyleSet_BuildFontFeatureValueSet(set:
RawServoStyleSetBorrowed,
list:
*mut gfxFontFeatureValueSet)
-> bool;
RawServoStyleSetBorrowed)
-> *mut gfxFontFeatureValueSet;
}
extern "C" {
pub fn Servo_StyleSet_ResolveForDeclarations(set:
@@ -47,6 +47,7 @@ use style::gecko_bindings::bindings::{ServoCssRulesBorrowed, ServoCssRulesStrong
use style::gecko_bindings::bindings::{nsACString, nsAString, nsCSSPropertyIDSetBorrowedMut};
use style::gecko_bindings::bindings::Gecko_AddPropertyToSet;
use style::gecko_bindings::bindings::Gecko_AppendPropertyValuePair;
use style::gecko_bindings::bindings::Gecko_ConstructFontFeatureValueSet;
use style::gecko_bindings::bindings::Gecko_GetOrCreateFinalKeyframe;
use style::gecko_bindings::bindings::Gecko_GetOrCreateInitialKeyframe;
use style::gecko_bindings::bindings::Gecko_GetOrCreateKeyframeAtStart;
@@ -3555,26 +3556,30 @@ pub extern "C" fn Servo_StyleSet_GetCounterStyleRule(raw_data: RawServoStyleSetB

#[no_mangle]
pub extern "C" fn Servo_StyleSet_BuildFontFeatureValueSet(
raw_data: RawServoStyleSetBorrowed,
set: *mut gfxFontFeatureValueSet
) -> bool {
raw_data: RawServoStyleSetBorrowed) -> *mut gfxFontFeatureValueSet {
let data = PerDocumentStyleData::from_ffi(raw_data).borrow();

let global_style_data = &*GLOBAL_STYLE_DATA;
let guard = global_style_data.shared_lock.read();

let has_rule = data.extra_style_data
.iter_origins()
.any(|(d, _)| !d.font_feature_values.is_empty());

if !has_rule {
return ptr::null_mut();
}

let font_feature_values_iter = data.extra_style_data
.iter_origins_rev()
.flat_map(|(d, _)| d.font_feature_values.iter());

let mut any_rule = false;
let set = unsafe { Gecko_ConstructFontFeatureValueSet() };
for src in font_feature_values_iter {
any_rule = true;
let rule = src.read_with(&guard);
rule.set_at_rules(set);
}

any_rule
set
}

#[no_mangle]

0 comments on commit dd8af18

Please sign in to comment.
You can’t perform that action at this time.