@@ -10,43 +10,52 @@ pub struct Buffer {
10
10
}
11
11
12
12
impl Buffer {
13
+ #[ inline]
13
14
pub fn with_capacity ( capacity : usize ) -> Self {
14
15
let buf = Box :: new_uninit_slice ( capacity) ;
15
16
Self { buf, pos : 0 , cap : 0 , init : 0 }
16
17
}
17
18
19
+ #[ inline]
18
20
pub fn buffer ( & self ) -> & [ u8 ] {
19
21
// SAFETY: self.cap is always <= self.init, so self.buf[self.pos..self.cap] is always init
20
22
// Additionally, both self.pos and self.cap are valid and and self.cap => self.pos, and
21
23
// that region is initialized because those are all invariants of this type.
22
24
unsafe { MaybeUninit :: slice_assume_init_ref ( & self . buf . get_unchecked ( self . pos ..self . cap ) ) }
23
25
}
24
26
27
+ #[ inline]
25
28
pub fn capacity ( & self ) -> usize {
26
29
self . buf . len ( )
27
30
}
28
31
32
+ #[ inline]
29
33
pub fn cap ( & self ) -> usize {
30
34
self . cap
31
35
}
32
36
37
+ #[ inline]
33
38
pub fn pos ( & self ) -> usize {
34
39
self . pos
35
40
}
36
41
42
+ #[ inline]
37
43
pub fn discard_buffer ( & mut self ) {
38
44
self . pos = 0 ;
39
45
self . cap = 0 ;
40
46
}
41
47
48
+ #[ inline]
42
49
pub fn consume ( & mut self , amt : usize ) {
43
50
self . pos = cmp:: min ( self . pos + amt, self . cap ) ;
44
51
}
45
52
53
+ #[ inline]
46
54
pub fn unconsume ( & mut self , amt : usize ) {
47
55
self . pos = self . pos . saturating_sub ( amt) ;
48
56
}
49
57
58
+ #[ inline]
50
59
pub fn fill_buf ( & mut self , mut reader : impl Read ) -> io:: Result < & [ u8 ] > {
51
60
// If we've reached the end of our internal buffer then we need to fetch
52
61
// some more data from the underlying reader.
0 commit comments