From 01b0718c60c93952231a128bf507fefa9a14c477 Mon Sep 17 00:00:00 2001 From: Rain Date: Thu, 2 Oct 2025 20:31:51 +0000 Subject: [PATCH] simplify BufList::chunks_vectored --- CHANGELOG.md | 5 +++++ src/cursor/mod.rs | 5 ++--- src/imp.rs | 13 ++++--------- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 854fda4..472069a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](https://semver.org). +## [1.1.2] - 2025-10-02 + +Simplify `Buf::chunks_vectored` implementations for `BufList` and `Cursor`. + ## [1.1.1] - 2025-10-01 ### Added @@ -74,6 +78,7 @@ This project adheres to [Semantic Versioning](https://semver.org). - Initial release. +[1.1.2]: https://github.com/sunshowers-code/buf-list/releases/tag/1.1.2 [1.1.1]: https://github.com/sunshowers-code/buf-list/releases/tag/1.1.1 [1.1.0]: https://github.com/sunshowers-code/buf-list/releases/tag/1.1.0 [1.0.3]: https://github.com/sunshowers-code/buf-list/releases/tag/1.0.3 diff --git a/src/cursor/mod.rs b/src/cursor/mod.rs index f90be78..265ee67 100644 --- a/src/cursor/mod.rs +++ b/src/cursor/mod.rs @@ -231,9 +231,8 @@ impl> Buf for Cursor { let to_fill = (iovs.len()).min(list.num_chunks() - current_chunk); for (i, iov) in iovs.iter_mut().enumerate().take(to_fill).skip(1) { *iov = IoSlice::new( - &list - .get_chunk(current_chunk + i) - .expect("chunk is in range")[..], + list.get_chunk(current_chunk + i) + .expect("chunk is in range"), ); } diff --git a/src/imp.rs b/src/imp.rs index 9c0bfd5..9304c82 100644 --- a/src/imp.rs +++ b/src/imp.rs @@ -217,17 +217,12 @@ impl Buf for BufList { return 0; } - // Loop over the buffers in the replay buffer list, and try to fill as - // many iovecs as we can from each buffer. - let mut filled = 0; - for buf in &self.bufs { - filled += buf.chunks_vectored(&mut iovs[filled..]); - if filled == iovs.len() { - return filled; - } + let to_fill = (iovs.len()).min(self.bufs.len()); + for (i, iov) in iovs.iter_mut().enumerate().take(to_fill) { + *iov = IoSlice::new(&self.bufs[i]); } - filled + to_fill } fn advance(&mut self, mut amt: usize) {