Skip to content

Commit b9497be

Browse files
committed
Allow Buffer methods to inline
1 parent 761ddf3 commit b9497be

File tree

1 file changed

+9
-0
lines changed
  • library/std/src/io/buffered/bufreader

1 file changed

+9
-0
lines changed

library/std/src/io/buffered/bufreader/buffer.rs

+9
Original file line numberDiff line numberDiff line change
@@ -10,43 +10,52 @@ pub struct Buffer {
1010
}
1111

1212
impl Buffer {
13+
#[inline]
1314
pub fn with_capacity(capacity: usize) -> Self {
1415
let buf = Box::new_uninit_slice(capacity);
1516
Self { buf, pos: 0, cap: 0, init: 0 }
1617
}
1718

19+
#[inline]
1820
pub fn buffer(&self) -> &[u8] {
1921
// SAFETY: self.cap is always <= self.init, so self.buf[self.pos..self.cap] is always init
2022
// Additionally, both self.pos and self.cap are valid and and self.cap => self.pos, and
2123
// that region is initialized because those are all invariants of this type.
2224
unsafe { MaybeUninit::slice_assume_init_ref(&self.buf.get_unchecked(self.pos..self.cap)) }
2325
}
2426

27+
#[inline]
2528
pub fn capacity(&self) -> usize {
2629
self.buf.len()
2730
}
2831

32+
#[inline]
2933
pub fn cap(&self) -> usize {
3034
self.cap
3135
}
3236

37+
#[inline]
3338
pub fn pos(&self) -> usize {
3439
self.pos
3540
}
3641

42+
#[inline]
3743
pub fn discard_buffer(&mut self) {
3844
self.pos = 0;
3945
self.cap = 0;
4046
}
4147

48+
#[inline]
4249
pub fn consume(&mut self, amt: usize) {
4350
self.pos = cmp::min(self.pos + amt, self.cap);
4451
}
4552

53+
#[inline]
4654
pub fn unconsume(&mut self, amt: usize) {
4755
self.pos = self.pos.saturating_sub(amt);
4856
}
4957

58+
#[inline]
5059
pub fn fill_buf(&mut self, mut reader: impl Read) -> io::Result<&[u8]> {
5160
// If we've reached the end of our internal buffer then we need to fetch
5261
// some more data from the underlying reader.

0 commit comments

Comments
 (0)