diff --git a/src/liballoc/slice.rs b/src/liballoc/slice.rs index 22da9dd6e9619..e012d56f48b48 100644 --- a/src/liballoc/slice.rs +++ b/src/liballoc/slice.rs @@ -589,7 +589,7 @@ impl> SliceConcatExt for [V] { type Output = Vec; fn concat(&self) -> Vec { - let size = self.iter().fold(0, |acc, v| acc + v.borrow().len()); + let size = self.iter().map(|slice| slice.borrow().len()).sum(); let mut result = Vec::with_capacity(size); for v in self { result.extend_from_slice(v.borrow()) @@ -603,8 +603,8 @@ impl> SliceConcatExt for [V] { Some(first) => first, None => return vec![], }; - let size = self.iter().fold(0, |acc, v| acc + v.borrow().len()); - let mut result = Vec::with_capacity(size + self.len()); + let size = self.iter().map(|slice| slice.borrow().len()).sum::() + self.len() - 1; + let mut result = Vec::with_capacity(size); result.extend_from_slice(first.borrow()); for v in iter {