summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_serialize/src/leb128.rs
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/rustc_serialize/src/leb128.rs')
-rw-r--r--compiler/rustc_serialize/src/leb128.rs16
1 files changed, 8 insertions, 8 deletions
diff --git a/compiler/rustc_serialize/src/leb128.rs b/compiler/rustc_serialize/src/leb128.rs
index 7dad9aa01..e568b9e67 100644
--- a/compiler/rustc_serialize/src/leb128.rs
+++ b/compiler/rustc_serialize/src/leb128.rs
@@ -1,3 +1,6 @@
+use crate::opaque::MemDecoder;
+use crate::serialize::Decoder;
+
/// Returns the length of the longest LEB128 encoding for `T`, assuming `T` is an integer type
pub const fn max_leb128_len<T>() -> usize {
// The longest LEB128 encoding for an integer uses 7 bits per byte.
@@ -50,21 +53,19 @@ impl_write_unsigned_leb128!(write_usize_leb128, usize);
macro_rules! impl_read_unsigned_leb128 {
($fn_name:ident, $int_ty:ty) => {
#[inline]
- pub fn $fn_name(slice: &[u8], position: &mut usize) -> $int_ty {
+ pub fn $fn_name(decoder: &mut MemDecoder<'_>) -> $int_ty {
// The first iteration of this loop is unpeeled. This is a
// performance win because this code is hot and integer values less
// than 128 are very common, typically occurring 50-80% or more of
// the time, even for u64 and u128.
- let byte = slice[*position];
- *position += 1;
+ let byte = decoder.read_u8();
if (byte & 0x80) == 0 {
return byte as $int_ty;
}
let mut result = (byte & 0x7F) as $int_ty;
let mut shift = 7;
loop {
- let byte = slice[*position];
- *position += 1;
+ let byte = decoder.read_u8();
if (byte & 0x80) == 0 {
result |= (byte as $int_ty) << shift;
return result;
@@ -127,14 +128,13 @@ impl_write_signed_leb128!(write_isize_leb128, isize);
macro_rules! impl_read_signed_leb128 {
($fn_name:ident, $int_ty:ty) => {
#[inline]
- pub fn $fn_name(slice: &[u8], position: &mut usize) -> $int_ty {
+ pub fn $fn_name(decoder: &mut MemDecoder<'_>) -> $int_ty {
let mut result = 0;
let mut shift = 0;
let mut byte;
loop {
- byte = slice[*position];
- *position += 1;
+ byte = decoder.read_u8();
result |= <$int_ty>::from(byte & 0x7F) << shift;
shift += 7;