diff options
| author | Donough Liu <liudingming@bytdance.com> | 2022-08-29 19:06:36 +0100 |
|---|---|---|
| committer | bogon-right <bogon-right@bytedance.com> | 2022-08-30 04:42:03 +0100 |
| commit | 97b1a6146c630374ddab15f424eb8141dbb88960 (patch) | |
| tree | 44b36c68cb488cf66023a8c5eda9fa788d117b38 /compiler/rustc_data_structures | |
| parent | b96fa1a25ced4cfa72923e6d45f47f36c2c00ce0 (diff) | |
| download | rust-97b1a6146c630374ddab15f424eb8141dbb88960.tar.gz rust-97b1a6146c630374ddab15f424eb8141dbb88960.zip | |
Use more `into_iter` rather than `drain(..)`
Diffstat (limited to 'compiler/rustc_data_structures')
| -rw-r--r-- | compiler/rustc_data_structures/src/sorted_map.rs | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/compiler/rustc_data_structures/src/sorted_map.rs b/compiler/rustc_data_structures/src/sorted_map.rs index 9efea1228ab..937cb671573 100644 --- a/compiler/rustc_data_structures/src/sorted_map.rs +++ b/compiler/rustc_data_structures/src/sorted_map.rs @@ -164,7 +164,7 @@ impl<K: Ord, V> SortedMap<K, V> { /// It is up to the caller to make sure that the elements are sorted by key /// and that there are no duplicates. #[inline] - pub fn insert_presorted(&mut self, mut elements: Vec<(K, V)>) { + pub fn insert_presorted(&mut self, elements: Vec<(K, V)>) { if elements.is_empty() { return; } @@ -173,28 +173,28 @@ impl<K: Ord, V> SortedMap<K, V> { let start_index = self.lookup_index_for(&elements[0].0); - let drain = match start_index { + let elements = match start_index { Ok(index) => { - let mut drain = elements.drain(..); - self.data[index] = drain.next().unwrap(); - drain + let mut elements = elements.into_iter(); + self.data[index] = elements.next().unwrap(); + elements } Err(index) => { if index == self.data.len() || elements.last().unwrap().0 < self.data[index].0 { // We can copy the whole range without having to mix with // existing elements. - self.data.splice(index..index, elements.drain(..)); + self.data.splice(index..index, elements.into_iter()); return; } - let mut drain = elements.drain(..); - self.data.insert(index, drain.next().unwrap()); - drain + let mut elements = elements.into_iter(); + self.data.insert(index, elements.next().unwrap()); + elements } }; // Insert the rest - for (k, v) in drain { + for (k, v) in elements { self.insert(k, v); } } |
