File tree Expand file tree Collapse file tree 2 files changed +17
-2
lines changed
library/proc_macro/src/bridge Expand file tree Collapse file tree 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> {
7878 mem:: take ( self )
7979 }
8080
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+
8196 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 ) {
8398 let b = self . take ( ) ;
8499 * self = ( b. reserve ) ( b, xs. len ( ) ) ;
85100 }
Original file line number Diff line number Diff line change @@ -27,7 +27,7 @@ macro_rules! rpc_encode_decode {
2727 ( le $ty: ty) => {
2828 impl <S > Encode <S > for $ty {
2929 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( ) ) ;
3131 }
3232 }
3333
You can’t perform that action at this time.
0 commit comments