Skip to content

Commit a65ce12

Browse files
authored
simplify BufList::chunks_vectored (#14)
1 parent 603087a commit a65ce12

File tree

3 files changed

+11
-12
lines changed

3 files changed

+11
-12
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
44

55
This project adheres to [Semantic Versioning](https://semver.org).
66

7+
## [1.1.2] - 2025-10-02
8+
9+
Simplify `Buf::chunks_vectored` implementations for `BufList` and `Cursor<T>`.
10+
711
## [1.1.1] - 2025-10-01
812

913
### Added
@@ -74,6 +78,7 @@ This project adheres to [Semantic Versioning](https://semver.org).
7478

7579
- Initial release.
7680

81+
[1.1.2]: https://github.com/sunshowers-code/buf-list/releases/tag/1.1.2
7782
[1.1.1]: https://github.com/sunshowers-code/buf-list/releases/tag/1.1.1
7883
[1.1.0]: https://github.com/sunshowers-code/buf-list/releases/tag/1.1.0
7984
[1.0.3]: https://github.com/sunshowers-code/buf-list/releases/tag/1.0.3

src/cursor/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,9 +231,8 @@ impl<T: AsRef<BufList>> Buf for Cursor<T> {
231231
let to_fill = (iovs.len()).min(list.num_chunks() - current_chunk);
232232
for (i, iov) in iovs.iter_mut().enumerate().take(to_fill).skip(1) {
233233
*iov = IoSlice::new(
234-
&list
235-
.get_chunk(current_chunk + i)
236-
.expect("chunk is in range")[..],
234+
list.get_chunk(current_chunk + i)
235+
.expect("chunk is in range"),
237236
);
238237
}
239238

src/imp.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -217,17 +217,12 @@ impl Buf for BufList {
217217
return 0;
218218
}
219219

220-
// Loop over the buffers in the replay buffer list, and try to fill as
221-
// many iovecs as we can from each buffer.
222-
let mut filled = 0;
223-
for buf in &self.bufs {
224-
filled += buf.chunks_vectored(&mut iovs[filled..]);
225-
if filled == iovs.len() {
226-
return filled;
227-
}
220+
let to_fill = (iovs.len()).min(self.bufs.len());
221+
for (i, iov) in iovs.iter_mut().enumerate().take(to_fill) {
222+
*iov = IoSlice::new(&self.bufs[i]);
228223
}
229224

230-
filled
225+
to_fill
231226
}
232227

233228
fn advance(&mut self, mut amt: usize) {

0 commit comments

Comments
 (0)