File tree 2 files changed +17
-2
lines changed
library/proc_macro/src/bridge
2 files changed +17
-2
lines changed Original file line number Diff line number Diff line change @@ -78,8 +78,23 @@ impl<T: Copy> Buffer<T> {
78
78
mem:: take ( self )
79
79
}
80
80
81
+ // We have the array method separate from extending from a slice. This is
82
+ // because in the case of small arrays, codegen can be more efficient
83
+ // (avoiding a memmove call). With extend_from_slice, LLVM at least
84
+ // currently is not able to make that optimization.
85
+ pub ( super ) fn extend_from_array < const N : usize > ( & mut self , xs : & [ T ; N ] ) {
86
+ if xs. len ( ) > ( self . capacity - self . len ) {
87
+ let b = self . take ( ) ;
88
+ * self = ( b. reserve ) ( b, xs. len ( ) ) ;
89
+ }
90
+ unsafe {
91
+ xs. as_ptr ( ) . copy_to_nonoverlapping ( self . data . add ( self . len ) , xs. len ( ) ) ;
92
+ self . len += xs. len ( ) ;
93
+ }
94
+ }
95
+
81
96
pub ( super ) fn extend_from_slice ( & mut self , xs : & [ T ] ) {
82
- if xs. len ( ) > self . capacity . wrapping_sub ( self . len ) {
97
+ if xs. len ( ) > ( self . capacity - self . len ) {
83
98
let b = self . take ( ) ;
84
99
* self = ( b. reserve ) ( b, xs. len ( ) ) ;
85
100
}
Original file line number Diff line number Diff line change @@ -27,7 +27,7 @@ macro_rules! rpc_encode_decode {
27
27
( le $ty: ty) => {
28
28
impl <S > Encode <S > for $ty {
29
29
fn encode( self , w: & mut Writer , _: & mut S ) {
30
- w. write_all ( & self . to_le_bytes( ) ) . unwrap ( ) ;
30
+ w. extend_from_array ( & self . to_le_bytes( ) ) ;
31
31
}
32
32
}
33
33
You can’t perform that action at this time.
0 commit comments