@@ -18,33 +18,39 @@ unsafe impl Sync for Buffer {}
18
18
unsafe impl Send for Buffer { }
19
19
20
20
impl Default for Buffer {
21
+ #[ inline]
21
22
fn default ( ) -> Self {
22
23
Self :: from ( vec ! [ ] )
23
24
}
24
25
}
25
26
26
27
impl Deref for Buffer {
27
28
type Target = [ u8 ] ;
29
+ #[ inline]
28
30
fn deref ( & self ) -> & [ u8 ] {
29
31
unsafe { slice:: from_raw_parts ( self . data as * const u8 , self . len ) }
30
32
}
31
33
}
32
34
33
35
impl DerefMut for Buffer {
36
+ #[ inline]
34
37
fn deref_mut ( & mut self ) -> & mut [ u8 ] {
35
38
unsafe { slice:: from_raw_parts_mut ( self . data , self . len ) }
36
39
}
37
40
}
38
41
39
42
impl Buffer {
43
+ #[ inline]
40
44
pub ( super ) fn new ( ) -> Self {
41
45
Self :: default ( )
42
46
}
43
47
48
+ #[ inline]
44
49
pub ( super ) fn clear ( & mut self ) {
45
50
self . len = 0 ;
46
51
}
47
52
53
+ #[ inline]
48
54
pub ( super ) fn take ( & mut self ) -> Self {
49
55
mem:: take ( self )
50
56
}
@@ -53,6 +59,7 @@ impl Buffer {
53
59
// because in the case of small arrays, codegen can be more efficient
54
60
// (avoiding a memmove call). With extend_from_slice, LLVM at least
55
61
// currently is not able to make that optimization.
62
+ #[ inline]
56
63
pub ( super ) fn extend_from_array < const N : usize > ( & mut self , xs : & [ u8 ; N ] ) {
57
64
if xs. len ( ) > ( self . capacity - self . len ) {
58
65
let b = self . take ( ) ;
@@ -64,6 +71,7 @@ impl Buffer {
64
71
}
65
72
}
66
73
74
+ #[ inline]
67
75
pub ( super ) fn extend_from_slice ( & mut self , xs : & [ u8 ] ) {
68
76
if xs. len ( ) > ( self . capacity - self . len ) {
69
77
let b = self . take ( ) ;
@@ -75,6 +83,7 @@ impl Buffer {
75
83
}
76
84
}
77
85
86
+ #[ inline]
78
87
pub ( super ) fn push ( & mut self , v : u8 ) {
79
88
// The code here is taken from Vec::push, and we know that reserve()
80
89
// will panic if we're exceeding isize::MAX bytes and so there's no need
@@ -91,22 +100,26 @@ impl Buffer {
91
100
}
92
101
93
102
impl Write for Buffer {
103
+ #[ inline]
94
104
fn write ( & mut self , xs : & [ u8 ] ) -> io:: Result < usize > {
95
105
self . extend_from_slice ( xs) ;
96
106
Ok ( xs. len ( ) )
97
107
}
98
108
109
+ #[ inline]
99
110
fn write_all ( & mut self , xs : & [ u8 ] ) -> io:: Result < ( ) > {
100
111
self . extend_from_slice ( xs) ;
101
112
Ok ( ( ) )
102
113
}
103
114
115
+ #[ inline]
104
116
fn flush ( & mut self ) -> io:: Result < ( ) > {
105
117
Ok ( ( ) )
106
118
}
107
119
}
108
120
109
121
impl Drop for Buffer {
122
+ #[ inline]
110
123
fn drop ( & mut self ) {
111
124
let b = self . take ( ) ;
112
125
( b. drop ) ( b) ;
0 commit comments