style: Avoid creating element data in Servo_ResolvePseudoStyle. r?bholley draft
authorEmilio Cobos Álvarez <emilio@crisal.io>
Thu, 28 Sep 2017 10:40:02 +0200
changeset 671790 716567420615722ff2bd6d869cc79106fa2d1ea8
parent 671789 1bbc5f1c1cbcc7c1da9ad46e85d8b135a9666ef3
child 671828 55cb82420fd6c0955fc8ed8f1054ea7a944c7ff8
push id82040
push userbmo:emilio@crisal.io
push dateThu, 28 Sep 2017 08:50:31 +0000
reviewersbholley
bugs1402285
milestone58.0a1
style: Avoid creating element data in Servo_ResolvePseudoStyle. r?bholley The reason the patch in bug 1402285 doesn't work is that we call this function multiple times with the same element. This fixes it. MozReview-Commit-ID: Ko9zirCOzTR
servo/ports/geckolib/glue.rs
--- a/servo/ports/geckolib/glue.rs
+++ b/servo/ports/geckolib/glue.rs
@@ -1767,31 +1767,38 @@ pub extern "C" fn Servo_ComputedValues_G
 pub extern "C" fn Servo_ResolvePseudoStyle(element: RawGeckoElementBorrowed,
                                            pseudo_type: CSSPseudoElementType,
                                            is_probe: bool,
                                            inherited_style: ServoStyleContextBorrowedOrNull,
                                            raw_data: RawServoStyleSetBorrowed)
      -> ServoStyleContextStrong
 {
     let element = GeckoElement(element);
-    let data = unsafe { element.ensure_data() };
     let doc_data = PerDocumentStyleData::from_ffi(raw_data).borrow();
 
     debug!("Servo_ResolvePseudoStyle: {:?} {:?}, is_probe: {}",
            element, PseudoElement::from_pseudo_type(pseudo_type), is_probe);
 
-    // FIXME(bholley): Assert against this.
-    if !data.has_styles() {
-        warn!("Calling Servo_ResolvePseudoStyle on unstyled element");
-        return if is_probe {
-            Strong::null()
-        } else {
-            doc_data.default_computed_values().clone().into()
-        };
-    }
+    let data = element.borrow_data();
+
+    let data = match data.as_ref() {
+        Some(data) if data.has_styles() => data,
+        _ => {
+            // FIXME(bholley, emilio): Assert against this.
+            //
+            // Known offender is nsMathMLmoFrame::MarkIntrinsicISizesDirty,
+            // which goes and does a bunch of work involving style resolution.
+            warn!("Calling Servo_ResolvePseudoStyle on unstyled element");
+            return if is_probe {
+                Strong::null()
+            } else {
+                doc_data.default_computed_values().clone().into()
+            };
+        }
+    };
 
     let pseudo = PseudoElement::from_pseudo_type(pseudo_type)
                     .expect("ResolvePseudoStyle with a non-pseudo?");
 
     let global_style_data = &*GLOBAL_STYLE_DATA;
     let guard = global_style_data.shared_lock.read();
     let style = get_pseudo_style(
         &guard,