Skip to content

Commit

Permalink
Simplify varint computation
Browse files Browse the repository at this point in the history
  • Loading branch information
maurolacy committed Oct 25, 2021
1 parent e478292 commit ec2f741
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions packages/cw0/src/parse_reply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ fn parse_protobuf_varint(data: &mut Vec<u8>, field_number: u8) -> Result<usize,
field_number
)));
}
len >>= 7;
len += ((data[i] & 0x7f) as u64) << 56;
len += ((data[i] & 0x7f) as u64) << (i * 7);
if data[i] & 0x80 == 0 {
break;
}
Expand All @@ -44,9 +43,7 @@ fn parse_protobuf_varint(data: &mut Vec<u8>, field_number: u8) -> Result<usize,
field_number
)));
}
i += 1;
len >>= (VARINT_MAX_BYTES - i) * 7;
*data = data.split_off(i);
*data = data.split_off(i + 1);

Ok(len as usize) // Gently fall back to the arch's max addressable size
}
Expand Down

0 comments on commit ec2f741

Please sign in to comment.