Skip to content

Commit

Permalink
perf(util): optimize <BufList as Buf>::has_remaining
Browse files Browse the repository at this point in the history
This allows short-circuiting when there is a non-empty chunk.
  • Loading branch information
tesaguri committed Sep 10, 2023
1 parent 63b67ae commit 10a9f72
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions http-body-util/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ impl<T: Buf> Buf for BufList<T> {
self.bufs.iter().map(|buf| buf.remaining()).sum()
}

#[inline]
fn has_remaining() -> bool {
self.bufs.iter().any(|buf| buf.has_remaining())
}

#[inline]
fn chunk(&self) -> &[u8] {
self.bufs.front().map(Buf::chunk).unwrap_or_default()
Expand Down

0 comments on commit 10a9f72

Please sign in to comment.