Move LayoutTask::first_reflow out of its Cell.

As the LayoutTask is uniquely owned, and we no longer have borrows of its
fields hanging around, we can use mutable references to simplify some code.
This commit is contained in:
Ms2ger 2015-11-06 13:15:28 +01:00
parent 3f4c734cf4
commit 8674345d61
2 changed files with 16 additions and 17 deletions

View file

@ -139,7 +139,7 @@ pub fn recalc_style_for_animations(flow: &mut Flow,
}
/// Handles animation updates.
pub fn tick_all_animations(layout_task: &LayoutTask, rw_data: &mut LayoutTaskData) {
pub fn tick_all_animations(layout_task: &mut LayoutTask, rw_data: &mut LayoutTaskData) {
layout_task.tick_animations(rw_data);
layout_task.script_chan

View file

@ -58,7 +58,6 @@ use selectors::parser::PseudoElement;
use sequential;
use serde_json;
use std::borrow::ToOwned;
use std::cell::Cell;
use std::collections::HashMap;
use std::collections::hash_state::DefaultState;
use std::mem::transmute;
@ -219,7 +218,7 @@ pub struct LayoutTask {
pub font_cache_task: FontCacheTask,
/// Is this the first reflow in this LayoutTask?
pub first_reflow: Cell<bool>,
pub first_reflow: bool,
/// To receive a canvas renderer associated to a layer, this message is propagated
/// to the paint chan
@ -428,7 +427,7 @@ impl LayoutTask {
mem_profiler_chan: mem_profiler_chan,
image_cache_task: image_cache_task.clone(),
font_cache_task: font_cache_task,
first_reflow: Cell::new(true),
first_reflow: true,
image_cache_receiver: image_cache_receiver,
image_cache_sender: ImageCacheChan(ipc_image_cache_sender),
font_cache_receiver: font_cache_receiver,
@ -461,7 +460,7 @@ impl LayoutTask {
}
/// Starts listening on the port.
fn start(self) {
fn start(mut self) {
let rw_data = self.rw_data.clone();
let mut possibly_locked_rw_data = Some(rw_data.lock().unwrap());
let mut rw_data = RwData {
@ -498,7 +497,7 @@ impl LayoutTask {
}
/// Receives and dispatches messages from the script and constellation tasks
fn handle_request<'a, 'b>(&self, possibly_locked_rw_data: &mut RwData<'a, 'b>) -> bool {
fn handle_request<'a, 'b>(&mut self, possibly_locked_rw_data: &mut RwData<'a, 'b>) -> bool {
enum Request {
FromPipeline(LayoutControlMsg),
FromScript(Msg),
@ -568,7 +567,7 @@ impl LayoutTask {
/// repaint.
/// TODO: In the future we could detect if the image size hasn't changed
/// since last time and avoid performing a complete layout pass.
fn repaint<'a, 'b>(&self, possibly_locked_rw_data: &mut RwData<'a, 'b>) -> bool {
fn repaint<'a, 'b>(&mut self, possibly_locked_rw_data: &mut RwData<'a, 'b>) -> bool {
let mut rw_data = possibly_locked_rw_data.lock();
let reflow_info = Reflow {
@ -590,7 +589,7 @@ impl LayoutTask {
}
/// Receives and dispatches messages from other tasks.
fn handle_request_helper<'a, 'b>(&self,
fn handle_request_helper<'a, 'b>(&mut self,
request: Msg,
possibly_locked_rw_data: &mut RwData<'a, 'b>)
-> bool {
@ -1085,7 +1084,7 @@ impl LayoutTask {
}
/// The high-level routine that performs layout tasks.
fn handle_reflow<'a, 'b>(&self,
fn handle_reflow<'a, 'b>(&mut self,
data: &ScriptReflow,
possibly_locked_rw_data: &mut RwData<'a, 'b>) {
// Make sure that every return path from this method joins the script task,
@ -1232,7 +1231,7 @@ impl LayoutTask {
}
}
fn set_visible_rects<'a, 'b>(&self,
fn set_visible_rects<'a, 'b>(&mut self,
new_visible_rects: Vec<(LayerId, Rect<Au>)>,
possibly_locked_rw_data: &mut RwData<'a, 'b>)
-> bool {
@ -1289,12 +1288,12 @@ impl LayoutTask {
true
}
fn tick_all_animations<'a, 'b>(&self, possibly_locked_rw_data: &mut RwData<'a, 'b>) {
fn tick_all_animations<'a, 'b>(&mut self, possibly_locked_rw_data: &mut RwData<'a, 'b>) {
let mut rw_data = possibly_locked_rw_data.lock();
animation::tick_all_animations(self, &mut rw_data)
}
pub fn tick_animations(&self, rw_data: &mut LayoutTaskData) {
pub fn tick_animations(&mut self, rw_data: &mut LayoutTaskData) {
let reflow_info = Reflow {
goal: ReflowGoal::ForDisplay,
page_clip_rect: MAX_RECT,
@ -1322,7 +1321,7 @@ impl LayoutTask {
&mut layout_context);
}
fn reflow_with_newly_loaded_web_font<'a, 'b>(&self, possibly_locked_rw_data: &mut RwData<'a, 'b>) {
fn reflow_with_newly_loaded_web_font<'a, 'b>(&mut self, possibly_locked_rw_data: &mut RwData<'a, 'b>) {
let mut rw_data = possibly_locked_rw_data.lock();
font_context::invalidate_font_caches();
@ -1345,7 +1344,7 @@ impl LayoutTask {
&mut layout_context);
}
fn perform_post_style_recalc_layout_passes<'a>(&'a self,
fn perform_post_style_recalc_layout_passes<'a>(&'a mut self,
data: &Reflow,
rw_data: &mut LayoutTaskData,
layout_context: &mut SharedLayoutContext) {
@ -1398,7 +1397,7 @@ impl LayoutTask {
}
}
fn perform_post_main_layout_passes<'a>(&'a self,
fn perform_post_main_layout_passes<'a>(&'a mut self,
data: &Reflow,
rw_data: &mut LayoutTaskData,
layout_context: &mut SharedLayoutContext) {
@ -1408,7 +1407,7 @@ impl LayoutTask {
&mut root_flow,
&mut *layout_context,
rw_data);
self.first_reflow.set(false);
self.first_reflow = false;
if opts::get().trace_layout {
layout_debug::end_trace();
@ -1456,7 +1455,7 @@ impl LayoutTask {
} else {
TimerMetadataFrameType::RootWindow
},
incremental: if self.first_reflow.get() {
incremental: if self.first_reflow {
TimerMetadataReflowType::FirstReflow
} else {
TimerMetadataReflowType::Incremental