Stop calling deref() and deref_mut() explicitly.

This commit is contained in:
Ms2ger 2015-01-22 14:49:14 +01:00
parent ee4c56bd8b
commit 13c7cf928a
14 changed files with 56 additions and 57 deletions

View file

@ -90,7 +90,7 @@ impl ConstructionResult {
match self {
&ConstructionResult::None => 0u,
&ConstructionResult::ConstructionItem(_) => 0u,
&ConstructionResult::Flow(ref flow_ref, _) => flow::base(flow_ref.deref()).debug_id(),
&ConstructionResult::Flow(ref flow_ref, _) => flow::base(&**flow_ref).debug_id(),
}
}
}
@ -376,7 +376,7 @@ impl<'a> FlowConstructor<'a> {
ConstructionResult::Flow(kid_flow, kid_abs_descendants) => {
// If kid_flow is TableCaptionFlow, kid_flow should be added under
// TableWrapperFlow.
if flow.is_table() && kid_flow.deref().is_table_caption() {
if flow.is_table() && kid_flow.is_table_caption() {
kid.set_flow_construction_result(ConstructionResult::Flow(kid_flow,
Descendants::new()))
} else if flow.need_anonymous_flow(&*kid_flow) {
@ -815,7 +815,7 @@ impl<'a> FlowConstructor<'a> {
for kid in node.children() {
match kid.swap_out_construction_result() {
ConstructionResult::Flow(mut kid_flow, _) => {
if kid_flow.deref().is_table_caption() &&
if kid_flow.is_table_caption() &&
kid_flow.as_block()
.fragment
.style()
@ -1377,10 +1377,10 @@ impl FlowConstructionUtils for FlowRef {
///
/// This must not be public because only the layout constructor can do this.
fn add_new_child(&mut self, mut new_child: FlowRef) {
let base = flow::mut_base(self.deref_mut());
let base = flow::mut_base(&mut **self);
{
let kid_base = flow::mut_base(new_child.deref_mut());
let kid_base = flow::mut_base(&mut *new_child);
kid_base.parallel.parent = parallel::mut_owned_flow_to_unsafe_flow(self);
}

View file

@ -879,7 +879,7 @@ impl FragmentDisplayListBuilding for Fragment {
let (sender, receiver) = channel::<Vec<u8>>();
let canvas_data = match canvas_fragment_info.renderer {
Some(ref renderer) => {
renderer.deref().lock().send(SendPixelContents(sender));
renderer.lock().send(SendPixelContents(sender));
receiver.recv()
},
None => repeat(0xFFu8).take(width * height * 4).collect(),
@ -1226,12 +1226,12 @@ impl InlineFlowDisplayListBuilding for InlineFlow {
&self.base.clip);
match fragment.specific {
SpecificFragmentInfo::InlineBlock(ref mut block_flow) => {
let block_flow = block_flow.flow_ref.deref_mut();
let block_flow = &mut *block_flow.flow_ref;
flow::mut_base(block_flow).display_list_building_result
.add_to(&mut *display_list)
}
SpecificFragmentInfo::InlineAbsoluteHypothetical(ref mut block_flow) => {
let block_flow = block_flow.flow_ref.deref_mut();
let block_flow = &mut *block_flow.flow_ref;
flow::mut_base(block_flow).display_list_building_result
.add_to(&mut *display_list)
}

View file

@ -26,25 +26,25 @@ impl FlowList {
/// Provide a reference to the front element, or None if the list is empty
#[inline]
pub fn front<'a>(&'a self) -> Option<&'a Flow> {
self.flows.front().map(|head| head.deref())
self.flows.front().map(|head| &**head)
}
/// Provide a mutable reference to the front element, or None if the list is empty
#[inline]
pub unsafe fn front_mut<'a>(&'a mut self) -> Option<&'a mut Flow> {
self.flows.front_mut().map(|head| head.deref_mut())
self.flows.front_mut().map(|head| &mut **head)
}
/// Provide a reference to the back element, or None if the list is empty
#[inline]
pub fn back<'a>(&'a self) -> Option<&'a Flow> {
self.flows.back().map(|tail| tail.deref())
self.flows.back().map(|tail| &**tail)
}
/// Provide a mutable reference to the back element, or None if the list is empty
#[inline]
pub unsafe fn back_mut<'a>(&'a mut self) -> Option<&'a mut Flow> {
self.flows.back_mut().map(|tail| tail.deref_mut())
self.flows.back_mut().map(|tail| &mut **tail)
}
/// Add an element first in the list
@ -108,7 +108,7 @@ impl FlowList {
impl<'a> Iterator<&'a (Flow + 'a)> for FlowListIterator<'a> {
#[inline]
fn next(&mut self) -> Option<&'a (Flow + 'a)> {
self.it.next().map(|x| x.deref())
self.it.next().map(|x| &**x)
}
#[inline]
@ -120,7 +120,7 @@ impl<'a> Iterator<&'a (Flow + 'a)> for FlowListIterator<'a> {
impl<'a> Iterator<&'a mut (Flow + 'a)> for MutFlowListIterator<'a> {
#[inline]
fn next(&mut self) -> Option<&'a mut (Flow + 'a)> {
self.it.next().map(|x| x.deref_mut())
self.it.next().map(|x| &mut **x)
}
#[inline]

View file

@ -75,7 +75,7 @@ impl Drop for FlowRef {
impl Clone for FlowRef {
fn clone(&self) -> FlowRef {
unsafe {
drop(flow::base(self.deref()).ref_count().fetch_add(1, Ordering::SeqCst));
drop(flow::base(&**self).ref_count().fetch_add(1, Ordering::SeqCst));
FlowRef {
object: raw::TraitObject {
vtable: self.object.vtable,

View file

@ -164,7 +164,7 @@ impl SpecificFragmentInfo {
SpecificFragmentInfo::InlineBlock(ref info) => &info.flow_ref,
};
flow::base(flow.deref()).restyle_damage
flow::base(&**flow).restyle_damage
}
pub fn get_type(&self) -> &'static str {
@ -1610,7 +1610,7 @@ impl Fragment {
}
SpecificFragmentInfo::InlineBlock(ref info) => {
// See CSS 2.1 § 10.8.1.
let block_flow = info.flow_ref.deref().as_immutable_block();
let block_flow = info.flow_ref.as_immutable_block();
let font_style = self.style.get_font_arc();
let font_metrics = text::font_metrics_for_style(layout_context.font_context(),
font_style);

View file

@ -1194,14 +1194,14 @@ impl Flow for InlineFlow {
&stacking_relative_border_box);
match fragment.specific {
SpecificFragmentInfo::InlineBlock(ref mut info) => {
flow::mut_base(info.flow_ref.deref_mut()).clip = clip;
flow::mut_base(&mut *info.flow_ref).clip = clip;
let block_flow = info.flow_ref.as_block();
block_flow.base.absolute_position_info = self.base.absolute_position_info;
block_flow.base.stacking_relative_position =
stacking_relative_border_box.origin;
}
SpecificFragmentInfo::InlineAbsoluteHypothetical(ref mut info) => {
flow::mut_base(info.flow_ref.deref_mut()).clip = clip;
flow::mut_base(&mut *info.flow_ref).clip = clip;
let block_flow = info.flow_ref.as_block();
block_flow.base.absolute_position_info = self.base.absolute_position_info;
block_flow.base.stacking_relative_position =

View file

@ -64,7 +64,7 @@ impl 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()));
let flow_trace = json::encode(&flow::base(&*state.flow_root));
let data = box ScopeData::new(name.clone(), flow_trace);
state.scope_stack.push(data);
}
@ -82,7 +82,7 @@ impl Drop for Scope {
match &mut *r.borrow_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);
}
@ -105,7 +105,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 = 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".to_owned(), flow_trace)],
flow_root: flow_root.clone(),
@ -121,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");

View file

@ -222,8 +222,8 @@ enum RWGuard<'a> {
impl<'a> Deref<LayoutTaskData> for RWGuard<'a> {
fn deref(&self) -> &LayoutTaskData {
match *self {
RWGuard::Held(ref x) => x.deref(),
RWGuard::Used(ref x) => x.deref(),
RWGuard::Held(ref x) => &**x,
RWGuard::Used(ref x) => &**x,
}
}
}
@ -231,8 +231,8 @@ impl<'a> Deref<LayoutTaskData> for RWGuard<'a> {
impl<'a> DerefMut<LayoutTaskData> for RWGuard<'a> {
fn deref_mut(&mut self) -> &mut LayoutTaskData {
match *self {
RWGuard::Held(ref mut x) => x.deref_mut(),
RWGuard::Used(ref mut x) => x.deref_mut(),
RWGuard::Held(ref mut x) => &mut **x,
RWGuard::Used(ref mut x) => &mut **x,
}
}
}
@ -462,7 +462,7 @@ impl LayoutTask {
{
let mut rw_data = self.lock_rw_data(possibly_locked_rw_data);
match rw_data.deref_mut().parallel_traversal {
match (&mut *rw_data).parallel_traversal {
None => {}
Some(ref mut traversal) => traversal.shutdown(),
}
@ -644,7 +644,7 @@ impl LayoutTask {
flow::mut_base(&mut **layout_root).clip =
ClippingRegion::from_rect(&data.page_clip_rect);
let rw_data = rw_data.deref_mut();
let rw_data = &mut **rw_data;
match rw_data.parallel_traversal {
None => {
sequential::build_display_list_for_subtree(layout_root, shared_layout_context);
@ -688,7 +688,7 @@ impl LayoutTask {
root_flow.position.size.to_physical(root_flow.writing_mode)
};
let mut display_list = box DisplayList::new();
flow::mut_base(layout_root.deref_mut()).display_list_building_result
flow::mut_base(&mut **layout_root).display_list_building_result
.add_to(&mut *display_list);
let paint_layer = Arc::new(PaintLayer::new(layout_root.layer_id(0),
color,
@ -748,7 +748,7 @@ impl LayoutTask {
rw_data.screen_size = current_screen_size;
// Create a layout context for use throughout the following passes.
let mut shared_layout_context = self.build_shared_layout_context(rw_data.deref(),
let mut shared_layout_context = self.build_shared_layout_context(&*rw_data,
node,
&data.url);
@ -773,7 +773,7 @@ impl LayoutTask {
if needs_reflow {
self.try_get_layout_root(*node).map(
|mut flow| LayoutTask::reflow_all_nodes(flow.deref_mut()));
|mut flow| LayoutTask::reflow_all_nodes(&mut *flow));
}
let mut layout_root = profile(TimeProfilerCategory::LayoutStyleRecalc,
@ -781,7 +781,7 @@ impl LayoutTask {
self.time_profiler_chan.clone(),
|| {
// Perform CSS selector matching and flow construction.
let rw_data = rw_data.deref_mut();
let rw_data = &mut *rw_data;
match rw_data.parallel_traversal {
None => {
sequential::traverse_dom_preorder(*node, &shared_layout_context);
@ -798,10 +798,9 @@ impl LayoutTask {
self.profiler_metadata(data),
self.time_profiler_chan.clone(),
|| {
if opts::get().nonincremental_layout || layout_root.deref_mut()
.compute_layout_damage()
if opts::get().nonincremental_layout || layout_root.compute_layout_damage()
.contains(REFLOW_ENTIRE_DOCUMENT) {
layout_root.deref_mut().reflow_entire_document()
layout_root.reflow_entire_document()
}
});
@ -820,7 +819,7 @@ impl LayoutTask {
self.profiler_metadata(data),
self.time_profiler_chan.clone(),
|| {
let rw_data = rw_data.deref_mut();
let rw_data = &mut *rw_data;
match rw_data.parallel_traversal {
None => {
// Sequential mode.

View file

@ -223,12 +223,12 @@ trait ParallelPostorderFlowTraversal : PostorderFlowTraversal {
let flow: &mut FlowRef = mem::transmute(&unsafe_flow);
// Perform the appropriate traversal.
if self.should_process(flow.deref_mut()) {
self.process(flow.deref_mut());
if self.should_process(&mut **flow) {
self.process(&mut **flow);
}
let base = flow::mut_base(flow.deref_mut());
let base = flow::mut_base(&mut **flow);
// Reset the count of children for the next layout traversal.
base.parallel.children_count.store(base.children.len() as int, Ordering::Relaxed);
@ -244,7 +244,7 @@ trait ParallelPostorderFlowTraversal : PostorderFlowTraversal {
// of our parent to finish processing? If so, we can continue
// on with our parent; otherwise, we've gotta wait.
let parent: &mut FlowRef = mem::transmute(&unsafe_parent);
let parent_base = flow::mut_base(parent.deref_mut());
let parent_base = flow::mut_base(&mut **parent);
if parent_base.parallel.children_count.fetch_sub(1, Ordering::SeqCst) == 1 {
// We were the last child of our parent. Reflow our parent.
unsafe_flow = unsafe_parent
@ -278,13 +278,13 @@ trait ParallelPreorderFlowTraversal : PreorderFlowTraversal {
// Get a real flow.
let flow: &mut FlowRef = mem::transmute(&unsafe_flow);
if self.should_process(flow.deref_mut()) {
if self.should_process(&mut **flow) {
// Perform the appropriate traversal.
self.process(flow.deref_mut());
self.process(&mut **flow);
}
// Possibly enqueue the children.
for kid in flow::child_iter(flow.deref_mut()) {
for kid in flow::child_iter(&mut **flow) {
had_children = true;
proxy.push(WorkUnit {
fun: top_down_func,
@ -427,7 +427,7 @@ pub fn traverse_flow_tree_preorder(root: &mut FlowRef,
if opts::get().bubble_inline_sizes_separately {
let layout_context = LayoutContext::new(shared_layout_context);
let bubble_inline_sizes = BubbleISizes { layout_context: &layout_context };
root.deref_mut().traverse_postorder(&bubble_inline_sizes);
root.traverse_postorder(&bubble_inline_sizes);
}
queue.data = shared_layout_context as *const _;

View file

@ -59,7 +59,7 @@ pub fn traverse_flow_tree_preorder(root: &mut FlowRef,
let layout_context = LayoutContext::new(shared_layout_context);
let root = root.deref_mut();
let root = &mut **root;
if opts::get().bubble_inline_sizes_separately {
let bubble_inline_sizes = BubbleISizes { layout_context: &layout_context };
@ -94,7 +94,7 @@ pub fn build_display_list_for_subtree(root: &mut FlowRef,
let compute_absolute_positions = ComputeAbsolutePositions { layout_context: &layout_context };
let build_display_list = BuildDisplayList { layout_context: &layout_context };
doit(root.deref_mut(), compute_absolute_positions, build_display_list);
doit(&mut **root, compute_absolute_positions, build_display_list);
}
pub fn iterate_through_flow_tree_fragment_border_boxes(root: &mut FlowRef,
@ -117,5 +117,5 @@ pub fn iterate_through_flow_tree_fragment_border_boxes(root: &mut FlowRef,
}
}
doit(root.deref_mut(), iterator, &ZERO_POINT);
doit(&mut **root, iterator, &ZERO_POINT);
}

View file

@ -634,7 +634,7 @@ impl<'a, T: Reflectable> JSRef<'a, T> {
impl<'a, T: Reflectable> Reflectable for JSRef<'a, T> {
fn reflector<'a>(&'a self) -> &'a Reflector {
self.deref().reflector()
(**self).reflector()
}
}

View file

@ -505,7 +505,7 @@ impl<'a> ElementHelpers<'a> for JSRef<'a, Element> {
fn update_inline_style(self, property_decl: style::PropertyDeclaration, style_priority: StylePriority) {
let mut inline_declarations = self.style_attribute().borrow_mut();
if let Some(ref mut declarations) = *inline_declarations.deref_mut() {
if let &Some(ref mut declarations) = &mut *inline_declarations {
let existing_declarations = if style_priority == StylePriority::Important {
declarations.important.make_unique()
} else {

View file

@ -515,7 +515,7 @@ impl<'a> NodeHelpers<'a> for JSRef<'a, Node> {
}
fn is_in_doc(self) -> bool {
self.deref().flags.get().contains(IS_IN_DOC)
self.flags.get().contains(IS_IN_DOC)
}
/// Returns the type ID of this node. Fails if this node is borrowed mutably.
@ -728,7 +728,7 @@ impl<'a> NodeHelpers<'a> for JSRef<'a, Node> {
}
fn to_trusted_node_address(self) -> TrustedNodeAddress {
TrustedNodeAddress(self.deref() as *const Node as *const libc::c_void)
TrustedNodeAddress(&*self as *const Node as *const libc::c_void)
}
fn get_bounding_content_box(self) -> Rect<Au> {
@ -1019,7 +1019,7 @@ pub struct NodeChildrenIterator<'a> {
impl<'a> Iterator<JSRef<'a, Node>> for NodeChildrenIterator<'a> {
fn next(&mut self) -> Option<JSRef<'a, Node>> {
let node = self.current;
self.current = node.and_then(|node| node.next_sibling().map(|node| *node.root().deref()));
self.current = node.and_then(|node| node.next_sibling().map(|node| *node.root()));
node
}
}
@ -1043,7 +1043,7 @@ pub struct AncestorIterator<'a> {
impl<'a> Iterator<JSRef<'a, Node>> for AncestorIterator<'a> {
fn next(&mut self) -> Option<JSRef<'a, Node>> {
let node = self.current;
self.current = node.and_then(|node| node.parent_node().map(|node| *node.root().deref()));
self.current = node.and_then(|node| node.parent_node().map(|node| *node.root()));
node
}
}

View file

@ -69,7 +69,7 @@ pub fn breakpoint() {
// Workaround for lack of `ptr_eq` on Arcs...
#[inline]
pub fn arc_ptr_eq<T: 'static + Send + Sync>(a: &Arc<T>, b: &Arc<T>) -> bool {
let a: &T = a.deref();
let b: &T = b.deref();
let a: &T = &**a;
let b: &T = &**b;
(a as *const T) == (b as *const T)
}