Skip to content

Commit

Permalink
slice: tweak concat & join
Browse files Browse the repository at this point in the history
  • Loading branch information
ljedrz committed Dec 3, 2018
1 parent a563ceb commit ae53273
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/liballoc/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ impl<T: Clone, V: Borrow<[T]>> SliceConcatExt<T> for [V] {
type Output = Vec<T>;

fn concat(&self) -> Vec<T> {
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())
Expand All @@ -603,8 +603,8 @@ impl<T: Clone, V: Borrow<[T]>> SliceConcatExt<T> 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::<usize>() + self.len() - 1;
let mut result = Vec::with_capacity(size);
result.extend_from_slice(first.borrow());

for v in iter {
Expand Down

0 comments on commit ae53273

Please sign in to comment.