Minor cleanup in compositing/constellation

* No need to explicitly state .iter()
* Simplify NavigationDirection match branches
* Utilize Vec.map instead of match
* Clean up a couple imports
This commit is contained in:
Corey Farwell 2015-03-17 22:39:54 -04:00
parent 755581ff54
commit 9101fa621a

View file

@ -22,8 +22,7 @@ use msg::constellation_msg::{FrameId, PipelineExitType, PipelineId};
use msg::constellation_msg::{SubpageId, WindowSizeData};
use msg::constellation_msg::Msg as ConstellationMsg;
use net::image_cache_task::{ImageCacheTask, ImageCacheTaskClient};
use net::resource_task::ResourceTask;
use net::resource_task;
use net::resource_task::{self, ResourceTask};
use net::storage_task::{StorageTask, StorageTaskMsg};
use util::cursor::Cursor;
use util::geometry::PagePx;
@ -32,7 +31,7 @@ use util::opts;
use util::task::spawn_named;
use util::time::TimeProfilerChan;
use std::borrow::ToOwned;
use std::collections::{HashMap};
use std::collections::HashMap;
use std::old_io as io;
use std::mem::replace;
use std::sync::mpsc::{Receiver, channel};
@ -144,15 +143,12 @@ struct FrameTreeIterator<'a> {
impl<'a> Iterator for FrameTreeIterator<'a> {
type Item = &'a Frame;
fn next(&mut self) -> Option<&'a Frame> {
match self.stack.pop() {
Some(next) => {
let frame = self.frames.get(&next).unwrap();
let pipeline = self.pipelines.get(&frame.current).unwrap();
self.stack.extend(pipeline.children.iter().map(|&c| c));
Some(frame)
}
None => None,
}
self.stack.pop().map(|next| {
let frame = self.frames.get(&next).unwrap();
let pipeline = self.pipelines.get(&frame.current).unwrap();
self.stack.extend(pipeline.children.iter().map(|&c| c));
frame
})
}
}
@ -380,7 +376,7 @@ impl<LTF: LayoutTaskFactory, STF: ScriptTaskFactory> Constellation<LTF, STF> {
}
fn handle_exit(&mut self) {
for (_id, ref pipeline) in self.pipelines.iter() {
for (_id, ref pipeline) in &self.pipelines {
pipeline.exit(PipelineExitType::Complete);
}
self.image_cache_task.exit();
@ -530,7 +526,7 @@ impl<LTF: LayoutTaskFactory, STF: ScriptTaskFactory> Constellation<LTF, STF> {
}
None => {
// Make sure no pending page would be overridden.
for frame_change in self.pending_frames.iter() {
for frame_change in &self.pending_frames {
if frame_change.old_pipeline_id == Some(source_id) {
// id that sent load msg is being changed already; abort
return;
@ -568,36 +564,27 @@ impl<LTF: LayoutTaskFactory, STF: ScriptTaskFactory> Constellation<LTF, STF> {
let (prev_pipeline_id, next_pipeline_id) = {
let frame = self.mut_frame(frame_id);
match direction {
let next = match direction {
NavigationDirection::Forward => {
if frame.next.is_empty() {
debug!("no next page to navigate to");
return;
} else {
let prev = frame.current;
frame.prev.push(frame.current);
let next = frame.next.pop().unwrap();
frame.current = next;
(prev, next)
}
frame.prev.push(frame.current);
frame.next.pop().unwrap()
}
NavigationDirection::Back => {
if frame.prev.is_empty() {
debug!("no previous page to navigate to");
return;
} else {
let prev = frame.current;
frame.next.push(frame.current);
let next = frame.prev.pop().unwrap();
frame.current = next;
(prev, next)
}
frame.next.push(frame.current);
frame.prev.pop().unwrap()
}
}
};
let prev = frame.current;
frame.current = next;
(prev, next)
};
// Suspend the old pipeline, and resume the new one.
@ -676,7 +663,7 @@ impl<LTF: LayoutTaskFactory, STF: ScriptTaskFactory> Constellation<LTF, STF> {
// Remove any evicted frames
if let Some(evicted_frames) = evicted_frames {
for pipeline_id in evicted_frames.iter() {
for pipeline_id in &evicted_frames {
self.close_pipeline(*pipeline_id, ExitPipelineMode::Normal);
}
}
@ -751,7 +738,7 @@ impl<LTF: LayoutTaskFactory, STF: ScriptTaskFactory> Constellation<LTF, STF> {
}
// Send resize message to any pending pipelines that aren't loaded yet.
for pending_frame in self.pending_frames.iter() {
for pending_frame in &self.pending_frames {
let pipeline = self.pipelines.get(&pending_frame.new_pipeline_id).unwrap();
if pipeline.parent_info.is_none() {
let ScriptControlChan(ref chan) = pipeline.script_chan;
@ -778,7 +765,7 @@ impl<LTF: LayoutTaskFactory, STF: ScriptTaskFactory> Constellation<LTF, STF> {
let pipeline = self.pipelines.remove(&pipeline_id).unwrap();
// Remove any child frames
for child in pipeline.children.iter() {
for child in &pipeline.children {
self.close_frame(*child, exit_mode);
}
@ -808,7 +795,7 @@ impl<LTF: LayoutTaskFactory, STF: ScriptTaskFactory> Constellation<LTF, STF> {
children: vec!(),
};
for child_frame_id in pipeline.children.iter() {
for child_frame_id in &pipeline.children {
frame_tree.children.push(self.frame_to_sendable(*child_frame_id));
}