Skip to content

Commit da3b2ca

Browse files
Provide raw &str access from Decoder
1 parent 68369a0 commit da3b2ca

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

compiler/rustc_serialize/src/opaque.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use crate::leb128::{self, max_leb128_len};
22
use crate::serialize::{self, Encoder as _};
3-
use std::borrow::Cow;
43
use std::convert::TryInto;
54
use std::fs::File;
65
use std::io::{self, Write};
@@ -663,15 +662,15 @@ impl<'a> serialize::Decoder for Decoder<'a> {
663662
}
664663

665664
#[inline]
666-
fn read_str(&mut self) -> Cow<'_, str> {
665+
fn read_str(&mut self) -> &str {
667666
let len = self.read_usize();
668667
let sentinel = self.data[self.position + len];
669668
assert!(sentinel == STR_SENTINEL);
670669
let s = unsafe {
671670
std::str::from_utf8_unchecked(&self.data[self.position..self.position + len])
672671
};
673672
self.position += len + 1;
674-
Cow::Borrowed(s)
673+
s
675674
}
676675

677676
#[inline]

compiler/rustc_serialize/src/serialize.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ pub trait Decoder {
198198
fn read_f64(&mut self) -> f64;
199199
fn read_f32(&mut self) -> f32;
200200
fn read_char(&mut self) -> char;
201-
fn read_str(&mut self) -> Cow<'_, str>;
201+
fn read_str(&mut self) -> &str;
202202
fn read_raw_bytes_into(&mut self, s: &mut [u8]);
203203
}
204204

@@ -313,7 +313,7 @@ impl<S: Encoder> Encodable<S> for String {
313313

314314
impl<D: Decoder> Decodable<D> for String {
315315
fn decode(d: &mut D) -> String {
316-
d.read_str().into_owned()
316+
d.read_str().to_owned()
317317
}
318318
}
319319

0 commit comments

Comments
 (0)