]> git.lizzy.rs Git - rust.git/blobdiff - compiler/rustc_serialize/src/opaque.rs
Auto merge of #93530 - anonion0:pthread_sigmask_fix, r=JohnTitor
[rust.git] / compiler / rustc_serialize / src / opaque.rs
index 7a05d2b762a47dfa0df44f4be783efe02b9ed519..5e5cbacbcff1a47c9551f9c6c76b99116f96b8c7 100644 (file)
@@ -1,6 +1,5 @@
 use crate::leb128::{self, max_leb128_len};
-use crate::serialize::{self, Encoder as _};
-use std::borrow::Cow;
+use crate::serialize::{self, Decoder as _, Encoder as _};
 use std::convert::TryInto;
 use std::fs::File;
 use std::io::{self, Write};
@@ -549,13 +548,6 @@ pub fn set_position(&mut self, pos: usize) {
     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 {
@@ -563,11 +555,6 @@ macro_rules! read_leb128 {
 }
 
 impl<'a> serialize::Decoder for Decoder<'a> {
-    #[inline]
-    fn read_unit(&mut self) -> () {
-        ()
-    }
-
     #[inline]
     fn read_u128(&mut self) -> u128 {
         read_leb128!(self, read_u128_leb128)
@@ -663,7 +650,7 @@ fn read_char(&mut self) -> char {
     }
 
     #[inline]
-    fn read_str(&mut self) -> Cow<'_, str> {
+    fn read_str(&mut self) -> &'a str {
         let len = self.read_usize();
         let sentinel = self.data[self.position + len];
         assert!(sentinel == STR_SENTINEL);
@@ -671,14 +658,14 @@ fn read_str(&mut self) -> Cow<'_, str> {
             std::str::from_utf8_unchecked(&self.data[self.position..self.position + len])
         };
         self.position += len + 1;
-        Cow::Borrowed(s)
+        s
     }
 
     #[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]
     }
 }
 
@@ -746,10 +733,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)
     }
 }