aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMitchell Hentges <mitchhentges@protonmail.com>2016-05-26 18:36:19 +0200
committerMitchell Hentges <mitchhentges@protonmail.com>2016-06-04 19:19:42 +0200
commit43396c027dcbc357f0fef674e55f9413f56f7535 (patch)
tree6d98fdc1512542243d072af548821c2910851893
parentd890453f786e2f6aa37095d9ed298cd11be0854d (diff)
downloadservo-43396c027dcbc357f0fef674e55f9413f56f7535.tar.gz
servo-43396c027dcbc357f0fef674e55f9413f56f7535.zip
Fragment debug_id u16 only exists in debug, prod will format mem address
-rw-r--r--components/layout/fragment.rs71
-rw-r--r--components/layout/layout_debug.rs3
2 files changed, 62 insertions, 12 deletions
diff --git a/components/layout/fragment.rs b/components/layout/fragment.rs
index f2da09b734c..9dd40bd56ad 100644
--- a/components/layout/fragment.rs
+++ b/components/layout/fragment.rs
@@ -22,6 +22,7 @@ use incremental::{RECONSTRUCT_FLOW, RestyleDamage};
use inline::{FIRST_FRAGMENT_OF_ELEMENT, InlineFragmentContext, InlineFragmentNodeInfo};
use inline::{InlineMetrics, LAST_FRAGMENT_OF_ELEMENT};
use ipc_channel::ipc::IpcSender;
+#[cfg(debug_assertions)]
use layout_debug;
use model::{self, IntrinsicISizes, IntrinsicISizesContribution, MaybeAuto, specified};
use msg::constellation_msg::PipelineId;
@@ -118,7 +119,9 @@ pub struct Fragment {
pub flags: FragmentFlags,
/// A debug ID that is consistent for the life of this fragment (via transform etc).
- pub debug_id: u16,
+ /// This ID should not be considered stable across multiple layouts or fragment
+ /// manipulations.
+ debug_id: DebugId,
/// The ID of the StackingContext that contains this fragment. This is initialized
/// to 0, but it assigned during the collect_stacking_contexts phase of display
@@ -129,7 +132,7 @@ pub struct Fragment {
impl Encodable for Fragment {
fn encode<S: Encoder>(&self, e: &mut S) -> Result<(), S::Error> {
e.emit_struct("fragment", 0, |e| {
- try!(e.emit_struct_field("id", 0, |e| self.debug_id().encode(e)));
+ try!(e.emit_struct_field("id", 0, |e| self.debug_id.encode(e)));
try!(e.emit_struct_field("border_box", 1, |e| self.border_box.encode(e)));
e.emit_struct_field("margin", 2, |e| self.margin.encode(e))
})
@@ -809,7 +812,7 @@ impl Fragment {
inline_context: None,
pseudo: node.get_pseudo_element_type().strip(),
flags: FragmentFlags::empty(),
- debug_id: layout_debug::generate_unique_debug_id(),
+ debug_id: DebugId::new(),
stacking_context_id: StackingContextId::new(0),
}
}
@@ -838,17 +841,11 @@ impl Fragment {
inline_context: None,
pseudo: pseudo,
flags: FragmentFlags::empty(),
- debug_id: layout_debug::generate_unique_debug_id(),
+ debug_id: DebugId::new(),
stacking_context_id: StackingContextId::new(0),
}
}
- /// Returns a debug ID of this fragment. This ID should not be considered stable across
- /// multiple layouts or fragment manipulations.
- pub fn debug_id(&self) -> u16 {
- self.debug_id
- }
-
/// Transforms this fragment into another fragment of the given type, with the given size,
/// preserving all the other data.
pub fn transform(&self, size: LogicalSize<Au>, info: SpecificFragmentInfo)
@@ -872,7 +869,7 @@ impl Fragment {
inline_context: self.inline_context.clone(),
pseudo: self.pseudo.clone(),
flags: FragmentFlags::empty(),
- debug_id: self.debug_id,
+ debug_id: self.debug_id.clone(),
stacking_context_id: StackingContextId::new(0),
}
}
@@ -2624,7 +2621,7 @@ impl fmt::Debug for Fragment {
write!(f, "{}({}) [{:?}] border_box={:?}{}{}{}",
self.specific.get_type(),
- self.debug_id(),
+ self.debug_id,
self.specific,
self.border_box,
border_padding_string,
@@ -2780,3 +2777,53 @@ pub struct SpeculatedInlineContentEdgeOffsets {
pub start: Au,
pub end: Au,
}
+
+#[cfg(not(debug_assertions))]
+#[derive(Clone)]
+struct DebugId;
+
+#[cfg(debug_assertions)]
+#[derive(Clone)]
+struct DebugId(u16);
+
+#[cfg(not(debug_assertions))]
+impl DebugId {
+ pub fn new() -> DebugId {
+ DebugId
+ }
+}
+
+#[cfg(debug_assertions)]
+impl DebugId {
+ pub fn new() -> DebugId {
+ DebugId(layout_debug::generate_unique_debug_id())
+ }
+}
+
+#[cfg(not(debug_assertions))]
+impl fmt::Display for DebugId {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ write!(f, "{:p}", &self)
+ }
+}
+
+#[cfg(debug_assertions)]
+impl fmt::Display for DebugId {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ write!(f, "{}", self.0)
+ }
+}
+
+#[cfg(not(debug_assertions))]
+impl Encodable for DebugId {
+ fn encode<S: Encoder>(&self, e: &mut S) -> Result<(), S::Error> {
+ e.emit_str(&format!("{:p}", &self))
+ }
+}
+
+#[cfg(debug_assertions)]
+impl Encodable for DebugId {
+ fn encode<S: Encoder>(&self, e: &mut S) -> Result<(), S::Error> {
+ e.emit_u16(self.0)
+ }
+}
diff --git a/components/layout/layout_debug.rs b/components/layout/layout_debug.rs
index 90b5870e468..20e8a16714b 100644
--- a/components/layout/layout_debug.rs
+++ b/components/layout/layout_debug.rs
@@ -15,10 +15,12 @@ use std::borrow::ToOwned;
use std::cell::RefCell;
use std::fs::File;
use std::io::Write;
+#[cfg(debug_assertions)]
use std::sync::atomic::{ATOMIC_USIZE_INIT, AtomicUsize, Ordering};
thread_local!(static STATE_KEY: RefCell<Option<State>> = RefCell::new(None));
+#[cfg(debug_assertions)]
static DEBUG_ID_COUNTER: AtomicUsize = ATOMIC_USIZE_INIT;
pub struct Scope;
@@ -96,6 +98,7 @@ impl Drop for Scope {
/// Generate a unique ID. This is used for items such as Fragment
/// which are often reallocated but represent essentially the
/// same data.
+#[cfg(debug_assertions)]
pub fn generate_unique_debug_id() -> u16 {
DEBUG_ID_COUNTER.fetch_add(1, Ordering::SeqCst) as u16
}