]> git.lizzy.rs Git - rust.git/commitdiff
Provide raw &str access from Decoder
authorMark Rousskov <mark.simulacrum@gmail.com>
Tue, 22 Feb 2022 23:05:51 +0000 (18:05 -0500)
committerMark Rousskov <mark.simulacrum@gmail.com>
Tue, 22 Feb 2022 23:05:51 +0000 (18:05 -0500)
compiler/rustc_serialize/src/opaque.rs
compiler/rustc_serialize/src/serialize.rs

index 7a05d2b762a47dfa0df44f4be783efe02b9ed519..8e2c866cd386c58dab53d7b1f6d511155c140856 100644 (file)
@@ -1,6 +1,5 @@
 use crate::leb128::{self, max_leb128_len};
 use crate::serialize::{self, Encoder as _};
-use std::borrow::Cow;
 use std::convert::TryInto;
 use std::fs::File;
 use std::io::{self, Write};
@@ -663,7 +662,7 @@ fn read_char(&mut self) -> char {
     }
 
     #[inline]
-    fn read_str(&mut self) -> Cow<'_, str> {
+    fn read_str(&mut self) -> &str {
         let len = self.read_usize();
         let sentinel = self.data[self.position + len];
         assert!(sentinel == STR_SENTINEL);
@@ -671,7 +670,7 @@ 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]
index a012be2857e1eb802aa1a7e0d004617663c6df6b..fbbd13657ba54de1b2ec4af4995a5ef812059d7f 100644 (file)
@@ -198,7 +198,7 @@ pub trait Decoder {
     fn read_f64(&mut self) -> f64;
     fn read_f32(&mut self) -> f32;
     fn read_char(&mut self) -> char;
-    fn read_str(&mut self) -> Cow<'_, str>;
+    fn read_str(&mut self) -> &str;
     fn read_raw_bytes_into(&mut self, s: &mut [u8]);
 }
 
@@ -313,7 +313,7 @@ fn encode(&self, s: &mut S) -> Result<(), S::Error> {
 
 impl<D: Decoder> Decodable<D> for String {
     fn decode(d: &mut D) -> String {
-        d.read_str().into_owned()
+        d.read_str().to_owned()
     }
 }