From e2db4fe46661c85029b28da43ff18e62099050c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Mon, 19 Sep 2016 14:20:39 +0200 Subject: 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. --- components/constellation/constellation.rs | 48 +++++++++++++++++-------------- 1 file 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 Constellation 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); + } } } } -- cgit v1.2.3