File tree Expand file tree Collapse file tree 1 file changed +11
-2
lines changed
compiler/rustc_serialize/src Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -54,8 +54,17 @@ macro_rules! impl_read_unsigned_leb128 {
5454 ( $fn_name: ident, $int_ty: ty) => {
5555 #[ inline]
5656 pub fn $fn_name( slice: & [ u8 ] , position: & mut usize ) -> $int_ty {
57- let mut result = 0 ;
58- let mut shift = 0 ;
57+ // The first iteration of this loop is unpeeled. This is a
58+ // performance win because this code is hot and integer values less
59+ // than 128 are very common, typically occurring 50-80% or more of
60+ // the time, even for u64 and u128.
61+ let byte = slice[ * position] ;
62+ * position += 1 ;
63+ if ( byte & 0x80 ) == 0 {
64+ return byte as $int_ty;
65+ }
66+ let mut result = ( byte & 0x7F ) as $int_ty;
67+ let mut shift = 7 ;
5968 loop {
6069 let byte = slice[ * position] ;
6170 * position += 1 ;
You can’t perform that action at this time.
0 commit comments