We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
self.len()
1 parent c853eba commit 763a05fCopy full SHA for 763a05f
commons/zenoh-buffers/src/lib.rs
@@ -106,17 +106,10 @@ pub mod buffer {
106
// the iterator has 1 element.
107
Cow::Borrowed(unsafe { slices.next().unwrap_unchecked() })
108
}
109
- _ => {
110
- let mut l = 0;
111
- for s in slices.by_ref() {
112
- l += s.len();
113
- }
114
- let mut vec = Vec::with_capacity(l);
115
- for slice in slices {
116
- vec.extend_from_slice(slice);
117
118
- Cow::Owned(vec)
119
+ _ => Cow::Owned(slices.fold(Vec::with_capacity(self.len()), |mut acc, it| {
+ acc.extend_from_slice(it);
+ acc
+ })),
120
121
122
0 commit comments