From 2a5b9c20fbf9cfd9c627d5b6651f5ca108292d29 Mon Sep 17 00:00:00 2001 From: Bobby Holley Date: Wed, 19 Jul 2017 21:02:28 -0700 Subject: [PATCH] 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 --HG-- extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear extra : subtree_revision : ed1e3f1a7d8600447fc6a7c446812399752aef60 --- servo/components/style/data.rs | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/servo/components/style/data.rs b/servo/components/style/data.rs index 0927edfc432d..47cf4c8a8af7 100644 --- a/servo/components/style/data.rs +++ b/servo/components/style/data.rs @@ -13,6 +13,7 @@ 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! { @@ -118,7 +119,7 @@ impl RestyleData { #[derive(Clone, Debug, Default)] pub struct EagerPseudoStyles(Option>); -#[derive(Debug, Default)] +#[derive(Default)] struct EagerPseudoArray(EagerPseudoArrayInner); type EagerPseudoArrayInner = [Option>; EAGER_PSEUDO_COUNT]; @@ -147,6 +148,20 @@ impl Clone for EagerPseudoArray { } } +// 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 { @@ -179,7 +194,7 @@ impl EagerPseudoStyles { /// 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>, @@ -204,6 +219,16 @@ impl ElementStyles { } } +// 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