mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
minor FP-style function refactor
This commit is contained in:
parent
c3d19c531b
commit
95f71f8fb9
1 changed files with 11 additions and 19 deletions
|
@ -51,14 +51,13 @@ struct FrameTree {
|
||||||
// Need to clone the FrameTrees, but _not_ the Pipelines
|
// Need to clone the FrameTrees, but _not_ the Pipelines
|
||||||
impl Clone for FrameTree {
|
impl Clone for FrameTree {
|
||||||
fn clone(&self) -> FrameTree {
|
fn clone(&self) -> FrameTree {
|
||||||
let mut children = ~[];
|
let mut children = do self.children.iter().transform |&frame_tree| {
|
||||||
for self.children.iter().advance |&frame_tree| {
|
@mut (*frame_tree).clone()
|
||||||
children.push(@mut (*frame_tree).clone());
|
};
|
||||||
}
|
|
||||||
FrameTree {
|
FrameTree {
|
||||||
pipeline: self.pipeline,
|
pipeline: self.pipeline,
|
||||||
parent: self.parent.clone(),
|
parent: self.parent.clone(),
|
||||||
children: children,
|
children: children.collect(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -88,11 +87,10 @@ impl FrameTree {
|
||||||
/// Returns the frame tree whose key is id
|
/// Returns the frame tree whose key is id
|
||||||
fn find_mut(@mut self, id: PipelineId) -> Option<@mut FrameTree> {
|
fn find_mut(@mut self, id: PipelineId) -> Option<@mut FrameTree> {
|
||||||
if self.pipeline.id == id { return Some(self); }
|
if self.pipeline.id == id { return Some(self); }
|
||||||
for self.children.iter().advance |frame_tree| {
|
let mut finder = do self.children.iter().filter_map |frame_tree| {
|
||||||
let found = frame_tree.find_mut(id);
|
frame_tree.find_mut(id)
|
||||||
if found.is_some() { return found; }
|
};
|
||||||
}
|
finder.next()
|
||||||
None
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Replaces a node of the frame tree in place. Returns the node that was removed or the original node
|
/// Replaces a node of the frame tree in place. Returns the node that was removed or the original node
|
||||||
|
@ -115,14 +113,10 @@ impl FrameTree {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn to_sendable(&self) -> SendableFrameTree {
|
fn to_sendable(&self) -> SendableFrameTree {
|
||||||
let mut sendable_frame_tree = SendableFrameTree {
|
let sendable_frame_tree = SendableFrameTree {
|
||||||
pipeline: (*self.pipeline).clone(),
|
pipeline: (*self.pipeline).clone(),
|
||||||
children: ~[],
|
children: self.children.iter().transform(|frame_tree| frame_tree.to_sendable()).collect(),
|
||||||
};
|
};
|
||||||
|
|
||||||
for self.children.iter().advance |frame_tree| {
|
|
||||||
sendable_frame_tree.children.push(frame_tree.to_sendable());
|
|
||||||
}
|
|
||||||
sendable_frame_tree
|
sendable_frame_tree
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -141,9 +135,7 @@ impl Iterator<@mut FrameTree> for FrameTreeIterator {
|
||||||
fn next(&mut self) -> Option<@mut FrameTree> {
|
fn next(&mut self) -> Option<@mut FrameTree> {
|
||||||
if !self.stack.is_empty() {
|
if !self.stack.is_empty() {
|
||||||
let next = self.stack.pop();
|
let next = self.stack.pop();
|
||||||
for next.children.iter().advance |&child| {
|
self.stack.push_all(next.children);
|
||||||
self.stack.push(child);
|
|
||||||
}
|
|
||||||
Some(next)
|
Some(next)
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue