Skip to content

Commit

Permalink
perf(s2n-quic-core): implement copy avoidance for reassembler
Browse files Browse the repository at this point in the history
  • Loading branch information
camshaft committed Feb 20, 2024
1 parent f745bc9 commit f617a2d
Show file tree
Hide file tree
Showing 8 changed files with 440 additions and 371 deletions.
20 changes: 20 additions & 0 deletions quic/s2n-quic-core/src/buffer/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,26 @@ pub trait Reader: Storage {
.map_or(false, |fin| fin == self.current_offset())
}

#[inline]
fn skip_until(&mut self, offset: VarInt) -> Result<(), Self::Error> {
ensure!(offset > self.current_offset(), Ok(()));

while let Some(len) = offset.checked_sub(self.current_offset()) {
let len = len.as_u64();

// we don't need to skip anything if the difference is 0
ensure!(len > 0, break);

// clamp the len to usize
let len = (usize::MAX as u64).min(len) as usize;
let _chunk = self.read_chunk(len)?;

ensure!(!self.buffer_is_empty(), break);
}

Ok(())
}

/// Limits the maximum offset that the caller can read from the reader
#[inline]
fn with_max_data(&mut self, max_data: VarInt) -> Limit<Self> {
Expand Down
Loading

0 comments on commit f617a2d

Please sign in to comment.