diff options
| author | Michael Goulet <michael@errs.io> | 2022-05-23 19:50:29 -0700 |
|---|---|---|
| committer | Michael Goulet <michael@errs.io> | 2022-05-23 19:50:29 -0700 |
| commit | 2b5e592b7af431d227b9aeb905118706beef3270 (patch) | |
| tree | d1a44b214595a6d3cfa3880811ad89a3266c6b2a | |
| parent | 14e5816f1bf051d922e8c46fa6e2414664cc3a22 (diff) | |
| download | rust-2b5e592b7af431d227b9aeb905118706beef3270.tar.gz rust-2b5e592b7af431d227b9aeb905118706beef3270.zip | |
Fix iterator implementation, add some inlines
| -rw-r--r-- | compiler/rustc_metadata/src/lib.rs | 1 | ||||
| -rw-r--r-- | compiler/rustc_metadata/src/rmeta/decoder.rs | 16 | ||||
| -rw-r--r-- | compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs | 6 |
3 files changed, 20 insertions, 3 deletions
diff --git a/compiler/rustc_metadata/src/lib.rs b/compiler/rustc_metadata/src/lib.rs index 3df18098a07..5e4c1284e24 100644 --- a/compiler/rustc_metadata/src/lib.rs +++ b/compiler/rustc_metadata/src/lib.rs @@ -10,6 +10,7 @@ #![feature(macro_metavar_expr)] #![feature(min_specialization)] #![feature(slice_as_chunks)] +#![feature(trusted_len)] #![feature(try_blocks)] #![feature(never_type)] #![recursion_limit = "256"] diff --git a/compiler/rustc_metadata/src/rmeta/decoder.rs b/compiler/rustc_metadata/src/rmeta/decoder.rs index 6042d0e49c3..72b7c08f04b 100644 --- a/compiler/rustc_metadata/src/rmeta/decoder.rs +++ b/compiler/rustc_metadata/src/rmeta/decoder.rs @@ -38,6 +38,7 @@ use rustc_span::{self, BytePos, ExpnId, Pos, Span, SyntaxContext, DUMMY_SP}; use proc_macro::bridge::client::ProcMacro; use std::io; +use std::iter::TrustedLen; use std::mem; use std::num::NonZeroUsize; use std::path::Path; @@ -277,17 +278,25 @@ struct DecodeIterator<'a, 'tcx, T> { impl<'a, 'tcx, T: Decodable<DecodeContext<'a, 'tcx>>> Iterator for DecodeIterator<'a, 'tcx, T> { type Item = T; + #[inline(always)] fn next(&mut self) -> Option<Self::Item> { self.elem_counter.next().map(|_| T::decode(&mut self.dcx)) } + + #[inline(always)] + fn size_hint(&self) -> (usize, Option<usize>) { + self.elem_counter.size_hint() + } } impl<'a, 'tcx, T: Decodable<DecodeContext<'a, 'tcx>>> ExactSizeIterator for DecodeIterator<'a, 'tcx, T> { - fn len(&self) -> usize { - self.elem_counter.len() - } +} + +unsafe impl<'a, 'tcx, T: Decodable<DecodeContext<'a, 'tcx>>> TrustedLen + for DecodeIterator<'a, 'tcx, T> +{ } impl<'a: 'x, 'tcx: 'x, 'x, T: Decodable<DecodeContext<'a, 'tcx>>> LazyArray<T> { @@ -321,6 +330,7 @@ impl<'a, 'tcx> DecodeContext<'a, 'tcx> { self.cdata().map_encoded_cnum_to_current(cnum) } + #[inline] fn read_lazy_offset_then<T>(&mut self, f: impl Fn(NonZeroUsize) -> T) -> T { let distance = self.read_usize(); let position = match self.lazy_state { diff --git a/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs b/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs index da2ac41af92..e3581a7607f 100644 --- a/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs +++ b/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs @@ -32,24 +32,28 @@ trait ProcessQueryValue<'tcx, T> { } impl<T> ProcessQueryValue<'_, Option<T>> for Option<T> { + #[inline(always)] fn process_decoded(self, _tcx: TyCtxt<'_>, _err: impl Fn() -> !) -> Option<T> { self } } impl<T> ProcessQueryValue<'_, T> for Option<T> { + #[inline(always)] fn process_decoded(self, _tcx: TyCtxt<'_>, err: impl Fn() -> !) -> T { if let Some(value) = self { value } else { err() } } } impl<'tcx, T: ArenaAllocatable<'tcx>> ProcessQueryValue<'tcx, &'tcx T> for Option<T> { + #[inline(always)] fn process_decoded(self, tcx: TyCtxt<'tcx>, err: impl Fn() -> !) -> &'tcx T { if let Some(value) = self { tcx.arena.alloc(value) } else { err() } } } impl<T, E> ProcessQueryValue<'_, Result<Option<T>, E>> for Option<T> { + #[inline(always)] fn process_decoded(self, _tcx: TyCtxt<'_>, _err: impl Fn() -> !) -> Result<Option<T>, E> { Ok(self) } @@ -58,12 +62,14 @@ impl<T, E> ProcessQueryValue<'_, Result<Option<T>, E>> for Option<T> { impl<'a, 'tcx, T: Copy + Decodable<DecodeContext<'a, 'tcx>>> ProcessQueryValue<'tcx, &'tcx [T]> for Option<DecodeIterator<'a, 'tcx, T>> { + #[inline(always)] fn process_decoded(self, tcx: TyCtxt<'tcx>, _err: impl Fn() -> !) -> &'tcx [T] { if let Some(iter) = self { tcx.arena.alloc_from_iter(iter) } else { &[] } } } impl ProcessQueryValue<'_, Option<DeprecationEntry>> for Option<Deprecation> { + #[inline(always)] fn process_decoded(self, _tcx: TyCtxt<'_>, _err: impl Fn() -> !) -> Option<DeprecationEntry> { self.map(DeprecationEntry::external) } |
