Skip to content

Commit

Permalink
Reformat truncation section of clone_from
Browse files Browse the repository at this point in the history
  • Loading branch information
crgl committed Jan 28, 2020
1 parent 81b6f8c commit 6c3e477
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/liballoc/collections/btree/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,20 +227,20 @@ impl<K: Clone + Ord, V: Clone> BTreeClone for BTreeMap<K, V> {
fn clone_from(&mut self, other: &Self) {
// This truncates `self` to `other.len()` by calling `split_off` on
// the first key after `other.len()` elements if it exists
if let Some(key) = {
if self.len() > other.len() {
let diff = self.len() - other.len();
if diff <= other.len() {
self.iter().nth_back(diff - 1).map(|pair| (*pair.0).clone())
} else {
self.iter().nth(other.len()).map(|pair| (*pair.0).clone())
}
let split_off_key = if self.len() > other.len() {
let diff = self.len() - other.len();
if diff <= other.len() {
self.iter().nth_back(diff - 1).map(|pair| (*pair.0).clone())
} else {
None
self.iter().nth(other.len()).map(|pair| (*pair.0).clone())
}
} {
} else {
None
};
if let Some(key) = split_off_key {
self.split_off(&key);
}

let mut siter = self.range_mut(..);
let mut oiter = other.iter();
// After truncation, `self` is at most as long as `other` so this loop
Expand Down

0 comments on commit 6c3e477

Please sign in to comment.