diff options
| author | Ben Kimock <kimockb@gmail.com> | 2022-07-20 18:21:15 -0400 |
|---|---|---|
| committer | Ben Kimock <kimockb@gmail.com> | 2022-07-24 12:50:05 -0400 |
| commit | b9497be7d0650915f75597738bb2715745fbe359 (patch) | |
| tree | 7168962566a2e7dc95885c2781b6142604a0c53f | |
| parent | 761ddf3e7fe2dea4e0dc437ffca24be8e529852b (diff) | |
| download | rust-b9497be7d0650915f75597738bb2715745fbe359.tar.gz rust-b9497be7d0650915f75597738bb2715745fbe359.zip | |
Allow Buffer methods to inline
| -rw-r--r-- | library/std/src/io/buffered/bufreader/buffer.rs | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/library/std/src/io/buffered/bufreader/buffer.rs b/library/std/src/io/buffered/bufreader/buffer.rs index 92fe47745d9..1989d85dfb5 100644 --- a/library/std/src/io/buffered/bufreader/buffer.rs +++ b/library/std/src/io/buffered/bufreader/buffer.rs @@ -10,11 +10,13 @@ pub struct Buffer { } impl Buffer { + #[inline] pub fn with_capacity(capacity: usize) -> Self { let buf = Box::new_uninit_slice(capacity); Self { buf, pos: 0, cap: 0, init: 0 } } + #[inline] pub fn buffer(&self) -> &[u8] { // SAFETY: self.cap is always <= self.init, so self.buf[self.pos..self.cap] is always init // Additionally, both self.pos and self.cap are valid and and self.cap => self.pos, and @@ -22,31 +24,38 @@ impl Buffer { unsafe { MaybeUninit::slice_assume_init_ref(&self.buf.get_unchecked(self.pos..self.cap)) } } + #[inline] pub fn capacity(&self) -> usize { self.buf.len() } + #[inline] pub fn cap(&self) -> usize { self.cap } + #[inline] pub fn pos(&self) -> usize { self.pos } + #[inline] pub fn discard_buffer(&mut self) { self.pos = 0; self.cap = 0; } + #[inline] pub fn consume(&mut self, amt: usize) { self.pos = cmp::min(self.pos + amt, self.cap); } + #[inline] pub fn unconsume(&mut self, amt: usize) { self.pos = self.pos.saturating_sub(amt); } + #[inline] pub fn fill_buf(&mut self, mut reader: impl Read) -> io::Result<&[u8]> { // If we've reached the end of our internal buffer then we need to fetch // some more data from the underlying reader. |
