From ae532730215f1e74b175d1aa214146e9d900e5fd Mon Sep 17 00:00:00 2001 From: ljedrz Date: Mon, 3 Dec 2018 16:22:27 +0100 Subject: [PATCH] slice: tweak concat & join --- src/liballoc/slice.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 {