Turn flow::base and friends into methods

This commit is contained in:
Matt Brubeck 2017-12-14 10:57:34 -06:00
parent 26feea3be5
commit c60cfc5a9f
20 changed files with 211 additions and 212 deletions

View file

@ -5,7 +5,7 @@
//! Supports writing a trace file created during each layout scope
//! that can be viewed by an external tool to make layout debugging easier.
use flow;
use flow::GetBaseFlow;
use flow_ref::FlowRef;
use serde_json::{to_string, to_value, Value};
use std::borrow::ToOwned;
@ -63,7 +63,7 @@ impl Scope {
pub fn new(name: String) -> Scope {
STATE_KEY.with(|ref r| {
if let Some(ref mut state) = *r.borrow_mut() {
let flow_trace = to_value(&flow::base(&*state.flow_root)).unwrap();
let flow_trace = to_value(&state.flow_root.base()).unwrap();
let data = Box::new(ScopeData::new(name.clone(), flow_trace));
state.scope_stack.push(data);
}
@ -78,7 +78,7 @@ impl Drop for Scope {
STATE_KEY.with(|ref r| {
if let Some(ref mut state) = *r.borrow_mut() {
let mut current_scope = state.scope_stack.pop().unwrap();
current_scope.post = to_value(&flow::base(&*state.flow_root)).unwrap();
current_scope.post = to_value(&state.flow_root.base()).unwrap();
let previous_scope = state.scope_stack.last_mut().unwrap();
previous_scope.children.push(current_scope);
}
@ -100,7 +100,7 @@ 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 = to_value(&flow::base(&*flow_root)).unwrap();
let flow_trace = to_value(&flow_root.base()).unwrap();
let state = State {
scope_stack: vec![Box::new(ScopeData::new("root".to_owned(), flow_trace))],
flow_root: flow_root.clone(),
@ -116,7 +116,7 @@ pub fn end_trace(generation: u32) {
let mut thread_state = STATE_KEY.with(|ref r| r.borrow_mut().take().unwrap());
assert!(thread_state.scope_stack.len() == 1);
let mut root_scope = thread_state.scope_stack.pop().unwrap();
root_scope.post = to_value(&flow::base(&*thread_state.flow_root)).unwrap();
root_scope.post = to_value(&thread_state.flow_root.base()).unwrap();
let result = to_string(&root_scope).unwrap();
let mut file = File::create(format!("layout_trace-{}.json", generation)).unwrap();