Skip to content

Commit

Permalink
Remove Traceable/Untraceable from node.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
Manishearth committed Oct 5, 2014
1 parent 5c8a45d commit a8f96dd
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 25 deletions.
6 changes: 3 additions & 3 deletions components/layout/util.rs
Expand Up @@ -77,20 +77,20 @@ pub trait LayoutDataAccess {
impl<'ln> LayoutDataAccess for LayoutNode<'ln> {
#[inline(always)]
unsafe fn borrow_layout_data_unchecked(&self) -> *const Option<LayoutDataWrapper> {
mem::transmute(self.get().layout_data.deref().borrow_unchecked())
mem::transmute(self.get().layout_data.borrow_unchecked())
}

#[inline(always)]
fn borrow_layout_data<'a>(&'a self) -> Ref<'a,Option<LayoutDataWrapper>> {
unsafe {
mem::transmute(self.get().layout_data.deref().borrow())
mem::transmute(self.get().layout_data.borrow())
}
}

#[inline(always)]
fn mutate_layout_data<'a>(&'a self) -> RefMut<'a,Option<LayoutDataWrapper>> {
unsafe {
mem::transmute(self.get().layout_data.deref().borrow_mut())
mem::transmute(self.get().layout_data.borrow_mut())
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions components/layout/wrapper.rs
Expand Up @@ -667,15 +667,15 @@ impl<'ln> ThreadSafeLayoutNode<'ln> {
#[inline(always)]
pub fn borrow_layout_data<'a>(&'a self) -> Ref<'a,Option<LayoutDataWrapper>> {
unsafe {
mem::transmute(self.get().layout_data.deref().borrow())
mem::transmute(self.get().layout_data.borrow())
}
}

/// Borrows the layout data mutably. Fails on a conflicting borrow.
#[inline(always)]
pub fn mutate_layout_data<'a>(&'a self) -> RefMut<'a,Option<LayoutDataWrapper>> {
unsafe {
mem::transmute(self.get().layout_data.deref().borrow_mut())
mem::transmute(self.get().layout_data.borrow_mut())
}
}

Expand Down
42 changes: 22 additions & 20 deletions components/script/dom/node.rs
Expand Up @@ -25,7 +25,7 @@ use dom::bindings::global;
use dom::bindings::js::{JS, JSRef, RootedReference, Temporary, Root};
use dom::bindings::js::{OptionalSettable, TemporaryPushable, OptionalRootedRootable};
use dom::bindings::js::{ResultRootable, OptionalRootable, MutNullableJS};
use dom::bindings::trace::{Traceable, Untraceable};
use dom::bindings::trace::JSTraceable;
use dom::bindings::utils;
use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
use dom::characterdata::CharacterData;
Expand Down Expand Up @@ -53,7 +53,7 @@ use servo_util::geometry::Au;
use servo_util::str::{DOMString, null_str_as_empty};
use style::{parse_selector_list_from_str, matches};

use js::jsapi::{JSContext, JSObject, JSRuntime};
use js::jsapi::{JSContext, JSObject, JSTracer, JSRuntime};
use js::jsfriendapi;
use libc;
use libc::uintptr_t;
Expand Down Expand Up @@ -102,13 +102,13 @@ pub struct Node {
child_list: MutNullableJS<NodeList>,

/// A bitfield of flags for node items.
flags: Traceable<RefCell<NodeFlags>>,
flags: RefCell<NodeFlags>,

/// Layout information. Only the layout task may touch this data.
///
/// Must be sent back to the layout task to be destroyed when this
/// node is finalized.
pub layout_data: Untraceable<LayoutDataRef>,
pub layout_data: LayoutDataRef,

unique_id: RefCell<String>,
}
Expand Down Expand Up @@ -189,6 +189,8 @@ pub struct LayoutDataRef {
pub data_cell: RefCell<Option<LayoutData>>,
}

untraceable!(LayoutDataRef)

impl LayoutDataRef {
pub fn new() -> LayoutDataRef {
LayoutDataRef {
Expand Down Expand Up @@ -453,7 +455,7 @@ impl<'a> NodeHelpers<'a> for JSRef<'a, Node> {
}

fn is_in_doc(self) -> bool {
self.deref().flags.deref().borrow().contains(IsInDoc)
self.deref().flags.borrow().contains(IsInDoc)
}

/// Returns the type ID of this node. Fails if this node is borrowed mutably.
Expand Down Expand Up @@ -512,38 +514,38 @@ impl<'a> NodeHelpers<'a> for JSRef<'a, Node> {
}

fn get_hover_state(self) -> bool {
self.flags.deref().borrow().contains(InHoverState)
self.flags.borrow().contains(InHoverState)
}

fn set_hover_state(self, state: bool) {
if state {
self.flags.deref().borrow_mut().insert(InHoverState);
self.flags.borrow_mut().insert(InHoverState);
} else {
self.flags.deref().borrow_mut().remove(InHoverState);
self.flags.borrow_mut().remove(InHoverState);
}
}

fn get_disabled_state(self) -> bool {
self.flags.deref().borrow().contains(InDisabledState)
self.flags.borrow().contains(InDisabledState)
}

fn set_disabled_state(self, state: bool) {
if state {
self.flags.deref().borrow_mut().insert(InDisabledState);
self.flags.borrow_mut().insert(InDisabledState);
} else {
self.flags.deref().borrow_mut().remove(InDisabledState);
self.flags.borrow_mut().remove(InDisabledState);
}
}

fn get_enabled_state(self) -> bool {
self.flags.deref().borrow().contains(InEnabledState)
self.flags.borrow().contains(InEnabledState)
}

fn set_enabled_state(self, state: bool) {
if state {
self.flags.deref().borrow_mut().insert(InEnabledState);
self.flags.borrow_mut().insert(InEnabledState);
} else {
self.flags.deref().borrow_mut().remove(InEnabledState);
self.flags.borrow_mut().remove(InEnabledState);
}
}

Expand Down Expand Up @@ -1034,9 +1036,9 @@ impl Node {
owner_doc: MutNullableJS::new(doc),
child_list: Default::default(),

flags: Traceable::new(RefCell::new(NodeFlags::new(type_id))),
flags: RefCell::new(NodeFlags::new(type_id)),

layout_data: Untraceable::new(LayoutDataRef::new()),
layout_data: LayoutDataRef::new(),

unique_id: RefCell::new("".to_string()),
}
Expand Down Expand Up @@ -1236,9 +1238,9 @@ impl Node {
let is_in_doc = parent.is_in_doc();
for kid in node.traverse_preorder() {
if is_in_doc {
kid.flags.deref().borrow_mut().insert(IsInDoc);
kid.flags.borrow_mut().insert(IsInDoc);
} else {
kid.flags.deref().borrow_mut().remove(IsInDoc);
kid.flags.borrow_mut().remove(IsInDoc);
}
}
}
Expand Down Expand Up @@ -1325,7 +1327,7 @@ impl Node {
// Step 8.
parent.remove_child(node);

node.deref().flags.deref().borrow_mut().remove(IsInDoc);
node.deref().flags.borrow_mut().remove(IsInDoc);

// Step 9.
match suppress_observers {
Expand Down Expand Up @@ -1449,7 +1451,7 @@ impl Node {
/// Sends layout data, if any, back to the layout task to be destroyed.
unsafe fn reap_layout_data(&mut self) {
if self.layout_data.is_present() {
let layout_data = mem::replace(self.layout_data.deref_mut(), LayoutDataRef::new());
let layout_data = mem::replace(&mut self.layout_data, LayoutDataRef::new());
let layout_chan = layout_data.take_chan();
match layout_chan {
None => {}
Expand Down

0 comments on commit a8f96dd

Please sign in to comment.