diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2016-09-19 07:29:11 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-09-19 07:29:11 -0500 |
commit | 55e459ca991ea982ecbaacd901bfcb01bffa6be2 (patch) | |
tree | 5cbfdf64e3033bc54b30577a9e7a47046d8c08a9 | |
parent | fe426f65b912dc091d0349c167086e19c72bbd25 (diff) | |
parent | e2db4fe46661c85029b28da43ff18e62099050c9 (diff) | |
download | servo-55e459ca991ea982ecbaacd901bfcb01bffa6be2.tar.gz servo-55e459ca991ea982ecbaacd901bfcb01bffa6be2.zip |
Auto merge of #13319 - emilio:constellation-refactoring, r=Ms2ger
constellation: Minor refactoring to aid legibility.
<!-- Please describe your changes on the following line: -->
---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
<!-- Either: -->
- [x] These changes do not require tests because refactor only
<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
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.
<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/13319)
<!-- Reviewable:end -->
-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); + } } } } |