Skip to content

Commit

Permalink
Auto merge of #19753 - bholley:notedirtyelement_optimizations, r=emilio
Browse files Browse the repository at this point in the history
  • Loading branch information
bors-servo committed Jan 12, 2018
2 parents 865181b + 2b1c1d7 commit 1a83665
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
4 changes: 4 additions & 0 deletions components/style/gecko/generated/bindings.rs
Expand Up @@ -1597,4 +1597,8 @@ extern "C" {
pub fn Gecko_GetElementsWithId ( aDocument : * const nsIDocument , aId : * mut nsAtom , ) -> * const nsTArray < * mut Element > ;
} extern "C" {
pub fn Gecko_GetBoolPrefValue ( pref_name : * const :: std :: os :: raw :: c_char , ) -> bool ;
} extern "C" {
pub fn Gecko_IsInServoTraversal ( ) -> bool ;
} extern "C" {
pub fn Gecko_IsMainThread ( ) -> bool ;
}
20 changes: 18 additions & 2 deletions ports/geckolib/glue.rs
Expand Up @@ -216,6 +216,16 @@ unsafe fn dummy_url_data() -> &'static RefPtr<URLExtraData> {
RefPtr::from_ptr_ref(&DUMMY_URL_DATA)
}

#[allow(dead_code)]
fn is_main_thread() -> bool {
unsafe { bindings::Gecko_IsMainThread() }
}

#[allow(dead_code)]
fn is_in_servo_traversal() -> bool {
unsafe { bindings::Gecko_IsInServoTraversal() }
}

fn create_shared_context<'a>(
global_style_data: &GlobalStyleData,
guard: &'a SharedRwLockReadGuard,
Expand Down Expand Up @@ -1014,8 +1024,13 @@ pub extern "C" fn Servo_Element_GetPseudoComputedValues(element: RawGeckoElement
#[no_mangle]
pub extern "C" fn Servo_Element_IsDisplayNone(element: RawGeckoElementBorrowed) -> bool {
let element = GeckoElement(element);
let data = element.borrow_data().expect("Invoking Servo_Element_IsDisplayNone on unstyled element");
data.styles.is_display_none()
let data = element.get_data().expect("Invoking Servo_Element_IsDisplayNone on unstyled element");

// This function is hot, so we bypass the AtomicRefCell. It would be nice to also assert that
// we're not in the servo traversal, but this function is called at various intermediate
// checkpoints when managing the traversal on the Gecko side.
debug_assert!(is_main_thread());
unsafe { &*data.as_ptr() }.styles.is_display_none()
}

#[no_mangle]
Expand Down Expand Up @@ -1335,6 +1350,7 @@ fn read_locked_arc<T, R, F>(raw: &<Locked<T> as HasFFI>::FFIType, func: F) -> R
unsafe fn read_locked_arc_unchecked<T, R, F>(raw: &<Locked<T> as HasFFI>::FFIType, func: F) -> R
where Locked<T>: HasArcFFI, F: FnOnce(&T) -> R
{
debug_assert!(is_main_thread() && !is_in_servo_traversal());
read_locked_arc(raw, func)
}

Expand Down

0 comments on commit 1a83665

Please sign in to comment.