Skip to content

Commit

Permalink
fix: use self.len() to prevent from consuming the slices iterator (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
YuanYuYuan authored May 14, 2024
1 parent c853eba commit 763a05f
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions commons/zenoh-buffers/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,10 @@ pub mod buffer {
// the iterator has 1 element.
Cow::Borrowed(unsafe { slices.next().unwrap_unchecked() })
}
_ => {
let mut l = 0;
for s in slices.by_ref() {
l += s.len();
}
let mut vec = Vec::with_capacity(l);
for slice in slices {
vec.extend_from_slice(slice);
}
Cow::Owned(vec)
}
_ => Cow::Owned(slices.fold(Vec::with_capacity(self.len()), |mut acc, it| {
acc.extend_from_slice(it);
acc
})),
}
}
}
Expand Down

0 comments on commit 763a05f

Please sign in to comment.