diff options
author | Emilio Cobos Álvarez <ecoal95@gmail.com> | 2016-09-19 14:20:39 +0200 |
---|---|---|
committer | Emilio Cobos Álvarez <ecoal95@gmail.com> | 2016-09-19 14:25:29 +0200 |
commit | e2db4fe46661c85029b28da43ff18e62099050c9 (patch) | |
tree | 5cbfdf64e3033bc54b30577a9e7a47046d8c08a9 | |
parent | fe426f65b912dc091d0349c167086e19c72bbd25 (diff) | |
download | servo-e2db4fe46661c85029b28da43ff18e62099050c9.tar.gz servo-e2db4fe46661c85029b28da43ff18e62099050c9.zip |
constellation: Minor refactoring to aid legibility.
Two things changed, on one hand, avoid a dumb if chain that could be more
idiomatically written with a match expression, and also avoiding use map() to
change state.
In general I'm pretty surprised for our lack of error reporting in this
critical code, but that's not the purpose of this PR.
-rw-r--r-- | components/constellation/constellation.rs | 48 |
1 files changed, 27 insertions, 21 deletions
diff --git a/components/constellation/constellation.rs b/components/constellation/constellation.rs index a57bc38dfd6..e501312e2d8 100644 --- a/components/constellation/constellation.rs +++ b/components/constellation/constellation.rs @@ -1924,28 +1924,34 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF> self.pipelines.get(&old_pipeline_id).and_then(|pipeline| pipeline.frame) }); - if let Some(frame_id) = frame_id { - // Add new pipeline to navigation frame, and return frames evicted from history. - self.pipelines.get_mut(&frame_change.new_pipeline_id) - .map(|pipeline| pipeline.frame = Some(frame_id)); - self.frames.get_mut(&frame_id).map(|frame| frame.load(frame_change.new_pipeline_id)); - } - - if let None = frame_id { - // The new pipeline is in a new frame with no history - let frame_id = self.new_frame(frame_change.new_pipeline_id); - - // If a child frame, add it to the parent pipeline. Otherwise - // it must surely be the root frame being created! - match self.pipelines.get(&frame_change.new_pipeline_id).and_then(|pipeline| pipeline.parent_info) { - Some((parent_id, _)) => { - if let Some(parent) = self.pipelines.get_mut(&parent_id) { - parent.add_child(frame_id); - } + match frame_id { + Some(frame_id) => { + // Add new pipeline to navigation frame, and return frames evicted from history. + if let Some(ref mut pipeline) = self.pipelines.get_mut(&frame_change.new_pipeline_id) { + pipeline.frame = Some(frame_id); } - None => { - assert!(self.root_frame_id.is_none()); - self.root_frame_id = Some(frame_id); + + if let Some(ref mut frame) = self.frames.get_mut(&frame_id) { + frame.load(frame_change.new_pipeline_id); + } + } + None => { + // The new pipeline is in a new frame with no history + let frame_id = self.new_frame(frame_change.new_pipeline_id); + + // If a child frame, add it to the parent pipeline. Otherwise + // it must surely be the root frame being created! + match self.pipelines.get(&frame_change.new_pipeline_id) + .and_then(|pipeline| pipeline.parent_info) { + Some((parent_id, _)) => { + if let Some(parent) = self.pipelines.get_mut(&parent_id) { + parent.add_child(frame_id); + } + } + None => { + assert!(self.root_frame_id.is_none()); + self.root_frame_id = Some(frame_id); + } } } } |