diff options
Diffstat (limited to 'compiler/rustc_serialize/src/opaque.rs')
| -rw-r--r-- | compiler/rustc_serialize/src/opaque.rs | 19 |
1 files changed, 6 insertions, 13 deletions
diff --git a/compiler/rustc_serialize/src/opaque.rs b/compiler/rustc_serialize/src/opaque.rs index 8e2c866cd38..1a71ee9038b 100644 --- a/compiler/rustc_serialize/src/opaque.rs +++ b/compiler/rustc_serialize/src/opaque.rs @@ -1,5 +1,5 @@ use crate::leb128::{self, max_leb128_len}; -use crate::serialize::{self, Encoder as _}; +use crate::serialize::{self, Decoder as _, Encoder as _}; use std::convert::TryInto; use std::fs::File; use std::io::{self, Write}; @@ -548,13 +548,6 @@ impl<'a> Decoder<'a> { pub fn advance(&mut self, bytes: usize) { self.position += bytes; } - - #[inline] - pub fn read_raw_bytes(&mut self, bytes: usize) -> &'a [u8] { - let start = self.position; - self.position += bytes; - &self.data[start..self.position] - } } macro_rules! read_leb128 { @@ -662,7 +655,7 @@ impl<'a> serialize::Decoder for Decoder<'a> { } #[inline] - fn read_str(&mut self) -> &str { + fn read_str(&mut self) -> &'a str { let len = self.read_usize(); let sentinel = self.data[self.position + len]; assert!(sentinel == STR_SENTINEL); @@ -674,10 +667,10 @@ impl<'a> serialize::Decoder for Decoder<'a> { } #[inline] - fn read_raw_bytes_into(&mut self, s: &mut [u8]) { + fn read_raw_bytes(&mut self, bytes: usize) -> &'a [u8] { let start = self.position; - self.position += s.len(); - s.copy_from_slice(&self.data[start..self.position]); + self.position += bytes; + &self.data[start..self.position] } } @@ -745,10 +738,10 @@ impl<'a> serialize::Decodable<Decoder<'a>> for IntEncodedWithFixedSize { fn decode(decoder: &mut Decoder<'a>) -> IntEncodedWithFixedSize { let _start_pos = decoder.position(); let bytes = decoder.read_raw_bytes(IntEncodedWithFixedSize::ENCODED_SIZE); + let value = u64::from_le_bytes(bytes.try_into().unwrap()); let _end_pos = decoder.position(); debug_assert_eq!((_end_pos - _start_pos), IntEncodedWithFixedSize::ENCODED_SIZE); - let value = u64::from_le_bytes(bytes.try_into().unwrap()); IntEncodedWithFixedSize(value) } } |
