mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-14 02:49:40 +00:00
Micro-optimize
This commit is contained in:
parent
2ae197d5fc
commit
e0103a7b3c
@ -250,6 +250,7 @@ impl<'a, 'tcx> Metadata<'a, 'tcx> for (CrateMetadataRef<'a>, TyCtxt<'tcx>) {
|
||||
}
|
||||
|
||||
impl<T: ParameterizedOverTcx> LazyValue<T> {
|
||||
#[inline]
|
||||
fn decode<'a, 'tcx, M: Metadata<'a, 'tcx>>(self, metadata: M) -> T::Value<'tcx>
|
||||
where
|
||||
T::Value<'tcx>: Decodable<DecodeContext<'a, 'tcx>>,
|
||||
@ -294,6 +295,7 @@ unsafe impl<'a, 'tcx, T: Decodable<DecodeContext<'a, 'tcx>>> TrustedLen
|
||||
}
|
||||
|
||||
impl<T: ParameterizedOverTcx> LazyArray<T> {
|
||||
#[inline]
|
||||
fn decode<'a, 'tcx, M: Metadata<'a, 'tcx>>(
|
||||
self,
|
||||
metadata: M,
|
||||
@ -420,6 +422,7 @@ impl<'a, 'tcx> TyDecoder for DecodeContext<'a, 'tcx> {
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> Decodable<DecodeContext<'a, 'tcx>> for CrateNum {
|
||||
#[inline]
|
||||
fn decode(d: &mut DecodeContext<'a, 'tcx>) -> CrateNum {
|
||||
let cnum = CrateNum::from_u32(d.read_u32());
|
||||
d.map_encoded_cnum_to_current(cnum)
|
||||
@ -427,18 +430,21 @@ impl<'a, 'tcx> Decodable<DecodeContext<'a, 'tcx>> for CrateNum {
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> Decodable<DecodeContext<'a, 'tcx>> for DefIndex {
|
||||
#[inline]
|
||||
fn decode(d: &mut DecodeContext<'a, 'tcx>) -> DefIndex {
|
||||
DefIndex::from_u32(d.read_u32())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> Decodable<DecodeContext<'a, 'tcx>> for ExpnIndex {
|
||||
#[inline]
|
||||
fn decode(d: &mut DecodeContext<'a, 'tcx>) -> ExpnIndex {
|
||||
ExpnIndex::from_u32(d.read_u32())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> Decodable<DecodeContext<'a, 'tcx>> for ast::AttrId {
|
||||
#[inline]
|
||||
fn decode(d: &mut DecodeContext<'a, 'tcx>) -> ast::AttrId {
|
||||
let sess = d.sess.expect("can't decode AttrId without Session");
|
||||
sess.parse_sess.attr_id_generator.mk_attr_id()
|
||||
@ -657,6 +663,7 @@ impl<'a, 'tcx, T> Decodable<DecodeContext<'a, 'tcx>> for LazyValue<T> {
|
||||
}
|
||||
|
||||
impl<'a, 'tcx, T> Decodable<DecodeContext<'a, 'tcx>> for LazyArray<T> {
|
||||
#[inline]
|
||||
fn decode(decoder: &mut DecodeContext<'a, 'tcx>) -> Self {
|
||||
let len = decoder.read_usize();
|
||||
if len == 0 { LazyArray::default() } else { decoder.read_lazy_array(len) }
|
||||
|
@ -480,7 +480,6 @@ where
|
||||
for<'tcx> T::Value<'tcx>: FixedSizeEncoding<ByteArray = [u8; N]>,
|
||||
{
|
||||
/// Given the metadata, extract out the value at a particular index (if any).
|
||||
#[inline(never)]
|
||||
pub(super) fn get<'a, 'tcx, M: Metadata<'a, 'tcx>>(&self, metadata: M, i: I) -> T::Value<'tcx> {
|
||||
trace!("LazyTable::lookup: index={:?} len={:?}", i, self.len);
|
||||
|
||||
@ -494,9 +493,13 @@ where
|
||||
let end = start + width;
|
||||
let bytes = &metadata.blob()[start..end];
|
||||
|
||||
let mut fixed = [0u8; N];
|
||||
fixed[..width].copy_from_slice(bytes);
|
||||
FixedSizeEncoding::from_bytes(&fixed)
|
||||
if let Ok(fixed) = bytes.try_into() {
|
||||
FixedSizeEncoding::from_bytes(fixed)
|
||||
} else {
|
||||
let mut fixed = [0u8; N];
|
||||
fixed[..width].copy_from_slice(bytes);
|
||||
FixedSizeEncoding::from_bytes(&fixed)
|
||||
}
|
||||
}
|
||||
|
||||
/// Size of the table in entries, including possible gaps.
|
||||
|
Loading…
Reference in New Issue
Block a user