servo: Merge #17791 - Bring back concise logging for ElementData (from bholley:less_verbose_cv); r=heycam
authorBobby Holley <bobbyholley@gmail.com>
Wed, 19 Jul 2017 21:02:28 -0700
changeset 418538 9043cd8fdee3f628f26d68ceae6c8d3de2936ffe
parent 418537 eb19a789a45562a03f9a105c874425cf8dac510e
child 418539 31ae02774ca909703e18c7b9f0a0f0a4f133e1ed
push id7566
push usermtabara@mozilla.com
push dateWed, 02 Aug 2017 08:25:16 +0000
treeherdermozilla-beta@86913f512c3c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersheycam
milestone56.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
servo: Merge #17791 - Bring back concise logging for ElementData (from bholley:less_verbose_cv); r=heycam This was removed recently in the ComputedValues patch, and makes traversal logging rather unusable. Reviewed in https://bugzilla.mozilla.org/show_bug.cgi?id=1382357 Source-Repo: https://github.com/servo/servo Source-Revision: 37d96f5ca9cf6df08dcb9a98455cbf297ec22cff
servo/components/style/data.rs
--- a/servo/components/style/data.rs
+++ b/servo/components/style/data.rs
@@ -8,16 +8,17 @@ use context::SharedStyleContext;
 use dom::TElement;
 use invalidation::element::restyle_hints::RestyleHint;
 use properties::ComputedValues;
 use properties::longhands::display::computed_value as display;
 use rule_tree::StrongRuleNode;
 use selector_parser::{EAGER_PSEUDO_COUNT, PseudoElement, RestyleDamage};
 use servo_arc::Arc;
 use shared_lock::StylesheetGuards;
+use std::fmt;
 use std::ops::{Deref, DerefMut};
 
 bitflags! {
     flags RestyleFlags: u8 {
         /// Whether the styles changed for this restyle.
         const WAS_RESTYLED = 1 << 0,
         /// Whether we reframed/reconstructed any ancestor or self.
         const ANCESTOR_WAS_RECONSTRUCTED = 1 << 1,
@@ -113,17 +114,17 @@ impl RestyleData {
 ///
 /// We use an Arc so that sharing these styles via the style sharing cache does
 /// not require duplicate allocations. We leverage the copy-on-write semantics of
 /// Arc::make_mut(), which is free (i.e. does not require atomic RMU operations)
 /// in servo_arc.
 #[derive(Clone, Debug, Default)]
 pub struct EagerPseudoStyles(Option<Arc<EagerPseudoArray>>);
 
-#[derive(Debug, Default)]
+#[derive(Default)]
 struct EagerPseudoArray(EagerPseudoArrayInner);
 type EagerPseudoArrayInner = [Option<Arc<ComputedValues>>; EAGER_PSEUDO_COUNT];
 
 impl Deref for EagerPseudoArray {
     type Target = EagerPseudoArrayInner;
     fn deref(&self) -> &Self::Target {
         &self.0
     }
@@ -142,16 +143,30 @@ impl Clone for EagerPseudoArray {
         let mut clone = Self::default();
         for i in 0..EAGER_PSEUDO_COUNT {
             clone[i] = self.0[i].clone();
         }
         clone
     }
 }
 
+// Override Debug to print which pseudos we have, and substitute the rule node
+// for the much-more-verbose ComputedValues stringification.
+impl fmt::Debug for EagerPseudoArray {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        write!(f, "EagerPseudoArray {{ ")?;
+        for i in 0..EAGER_PSEUDO_COUNT {
+            if let Some(ref values) = self[i] {
+                write!(f, "{:?}: {:?}, ", PseudoElement::from_eager_index(i), &values.rules)?;
+            }
+        }
+        write!(f, "}}")
+    }
+}
+
 impl EagerPseudoStyles {
     /// Returns whether there are any pseudo styles.
     pub fn is_empty(&self) -> bool {
         self.0.is_none()
     }
 
     /// Grabs a reference to the list of styles, if they exist.
     pub fn as_array(&self) -> Option<&EagerPseudoArrayInner> {
@@ -174,17 +189,17 @@ impl EagerPseudoStyles {
         }
         let arr = Arc::make_mut(self.0.as_mut().unwrap());
         arr[pseudo.eager_index()] = Some(value);
     }
 }
 
 /// The styles associated with a node, including the styles for any
 /// pseudo-elements.
-#[derive(Clone, Debug, Default)]
+#[derive(Clone, Default)]
 pub struct ElementStyles {
     /// The element's style.
     pub primary: Option<Arc<ComputedValues>>,
     /// A list of the styles for the element's eagerly-cascaded pseudo-elements.
     pub pseudos: EagerPseudoStyles,
 }
 
 impl ElementStyles {
@@ -199,16 +214,26 @@ impl ElementStyles {
     }
 
     /// Whether this element `display` value is `none`.
     pub fn is_display_none(&self) -> bool {
         self.primary().get_box().clone_display() == display::T::none
     }
 }
 
+// We manually implement Debug for ElementStyles so that we can avoid the
+// verbose stringification of every property in the ComputedValues. We
+// substitute the rule node instead.
+impl fmt::Debug for ElementStyles {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        write!(f, "ElementStyles {{ primary: {:?}, pseudos: {:?} }}",
+               self.primary.as_ref().map(|x| &x.rules), self.pseudos)
+    }
+}
+
 /// Style system data associated with an Element.
 ///
 /// In Gecko, this hangs directly off the Element. Servo, this is embedded
 /// inside of layout data, which itself hangs directly off the Element. In
 /// both cases, it is wrapped inside an AtomicRefCell to ensure thread safety.
 #[derive(Debug, Default)]
 pub struct ElementData {
     /// The styles for the element and its pseudo-elements.