Skip to content

Commit

Permalink
perf(util): optimize <BufList as Buf>::has_remaining (#94)
Browse files Browse the repository at this point in the history
This returns true much faster than summing _all_ bufs in the list.
  • Loading branch information
tesaguri authored Feb 21, 2024
1 parent 70ba87f commit bffa8c5
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(&self) -> 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 bffa8c5

Please sign in to comment.