diff options
| author | Nicholas Nethercote <n.nethercote@gmail.com> | 2023-04-28 08:37:11 +1000 |
|---|---|---|
| committer | Nicholas Nethercote <n.nethercote@gmail.com> | 2023-04-28 09:50:21 +1000 |
| commit | b51deba9ac36ee2808af8a03fe8bc6fc570cc497 (patch) | |
| tree | 8e4163dd9e9a1f67da7e96414739b5bdda692798 /compiler/rustc_serialize | |
| parent | c14882f74e8feb3f76ae85ed5cd66afaccd1da67 (diff) | |
| download | rust-b51deba9ac36ee2808af8a03fe8bc6fc570cc497.tar.gz rust-b51deba9ac36ee2808af8a03fe8bc6fc570cc497.zip | |
Remove `MemDecoder::read_raw_bytes_inherent`.
It's unnecessary. Note that `MemDecoder::read_raw_bytes` how has a `&'a [u8]` return type, the same as what `read_raw_bytes_inherent` had.
Diffstat (limited to 'compiler/rustc_serialize')
| -rw-r--r-- | compiler/rustc_serialize/src/opaque.rs | 30 |
1 files changed, 11 insertions, 19 deletions
diff --git a/compiler/rustc_serialize/src/opaque.rs b/compiler/rustc_serialize/src/opaque.rs index b7976ea3b1c..012a6406de3 100644 --- a/compiler/rustc_serialize/src/opaque.rs +++ b/compiler/rustc_serialize/src/opaque.rs @@ -573,22 +573,6 @@ impl<'a> MemDecoder<'a> { self.read_raw_bytes(N).try_into().unwrap() } - // The trait method doesn't have a lifetime parameter, and we need a version of this - // that definitely returns a slice based on the underlying storage as opposed to - // the Decoder itself in order to implement read_str efficiently. - #[inline] - fn read_raw_bytes_inherent(&mut self, bytes: usize) -> &'a [u8] { - if bytes > self.remaining() { - Self::decoder_exhausted(); - } - // SAFETY: We just checked if this range is in-bounds above. - unsafe { - let slice = std::slice::from_raw_parts(self.current, bytes); - self.current = self.current.add(bytes); - slice - } - } - /// While we could manually expose manipulation of the decoder position, /// all current users of that method would need to reset the position later, /// incurring the bounds check of set_position twice. @@ -706,14 +690,22 @@ impl<'a> Decoder for MemDecoder<'a> { #[inline] fn read_str(&mut self) -> &str { let len = self.read_usize(); - let bytes = self.read_raw_bytes_inherent(len + 1); + let bytes = self.read_raw_bytes(len + 1); assert!(bytes[len] == STR_SENTINEL); unsafe { std::str::from_utf8_unchecked(&bytes[..len]) } } #[inline] - fn read_raw_bytes(&mut self, bytes: usize) -> &[u8] { - self.read_raw_bytes_inherent(bytes) + fn read_raw_bytes(&mut self, bytes: usize) -> &'a [u8] { + if bytes > self.remaining() { + Self::decoder_exhausted(); + } + // SAFETY: We just checked if this range is in-bounds above. + unsafe { + let slice = std::slice::from_raw_parts(self.current, bytes); + self.current = self.current.add(bytes); + slice + } } #[inline] |
