diff options
Diffstat (limited to 'components/layout/layout_debug.rs')
-rw-r--r-- | components/layout/layout_debug.rs | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/components/layout/layout_debug.rs b/components/layout/layout_debug.rs index 94ddad456f6..5f0851b1f36 100644 --- a/components/layout/layout_debug.rs +++ b/components/layout/layout_debug.rs @@ -10,13 +10,15 @@ use flow_ref::FlowRef; use flow; use serialize::json; + +use std::borrow::ToOwned; use std::cell::RefCell; use std::io::File; -use std::sync::atomic::{AtomicUint, SeqCst, INIT_ATOMIC_UINT}; +use std::sync::atomic::{AtomicUint, Ordering, ATOMIC_UINT_INIT}; -thread_local!(static STATE_KEY: RefCell<Option<State>> = RefCell::new(None)) +thread_local!(static STATE_KEY: RefCell<Option<State>> = RefCell::new(None)); -static mut DEBUG_ID_COUNTER: AtomicUint = INIT_ATOMIC_UINT; +static mut DEBUG_ID_COUNTER: AtomicUint = ATOMIC_UINT_INIT; pub struct Scope; @@ -29,9 +31,9 @@ macro_rules! layout_debug_scope( layout_debug::Scope } ) -) +); -#[deriving(Encodable)] +#[derive(RustcEncodable)] struct ScopeData { name: String, pre: String, @@ -61,12 +63,12 @@ impl Scope { pub fn new(name: String) -> Scope { STATE_KEY.with(|ref r| { match &mut *r.borrow_mut() { - &Some(ref mut state) => { - let flow_trace = json::encode(&flow::base(state.flow_root.deref())); + &mut Some(ref mut state) => { + let flow_trace = json::encode(&flow::base(&*state.flow_root)); let data = box ScopeData::new(name.clone(), flow_trace); state.scope_stack.push(data); } - &None => {} + &mut None => {} } }); Scope @@ -78,13 +80,13 @@ impl Drop for Scope { fn drop(&mut self) { STATE_KEY.with(|ref r| { match &mut *r.borrow_mut() { - &Some(ref mut state) => { + &mut Some(ref mut state) => { let mut current_scope = state.scope_stack.pop().unwrap(); - current_scope.post = json::encode(&flow::base(state.flow_root.deref())); + current_scope.post = json::encode(&flow::base(&*state.flow_root)); let previous_scope = state.scope_stack.last_mut().unwrap(); previous_scope.children.push(current_scope); } - &None => {} + &mut None => {} } }); } @@ -94,7 +96,7 @@ impl Drop for Scope { /// which are often reallocated but represent essentially the /// same data. pub fn generate_unique_debug_id() -> u16 { - unsafe { DEBUG_ID_COUNTER.fetch_add(1, SeqCst) as u16 } + unsafe { DEBUG_ID_COUNTER.fetch_add(1, Ordering::SeqCst) as u16 } } /// Begin a layout debug trace. If this has not been called, @@ -103,9 +105,9 @@ pub fn begin_trace(flow_root: FlowRef) { assert!(STATE_KEY.with(|ref r| r.borrow().is_none())); STATE_KEY.with(|ref r| { - let flow_trace = json::encode(&flow::base(flow_root.deref())); + let flow_trace = json::encode(&flow::base(&*flow_root)); let state = State { - scope_stack: vec![box ScopeData::new("root".into_string(), flow_trace)], + scope_stack: vec![box ScopeData::new("root".to_owned(), flow_trace)], flow_root: flow_root.clone(), }; *r.borrow_mut() = Some(state); @@ -119,7 +121,7 @@ pub fn end_trace() { let mut task_state = STATE_KEY.with(|ref r| r.borrow_mut().take().unwrap()); assert!(task_state.scope_stack.len() == 1); let mut root_scope = task_state.scope_stack.pop().unwrap(); - root_scope.post = json::encode(&flow::base(task_state.flow_root.deref())); + root_scope.post = json::encode(&flow::base(&*task_state.flow_root)); let result = json::encode(&root_scope); let path = Path::new("layout_trace.json"); |