mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-06 12:18:33 +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> {
|
impl<T: ParameterizedOverTcx> LazyValue<T> {
|
||||||
|
#[inline]
|
||||||
fn decode<'a, 'tcx, M: Metadata<'a, 'tcx>>(self, metadata: M) -> T::Value<'tcx>
|
fn decode<'a, 'tcx, M: Metadata<'a, 'tcx>>(self, metadata: M) -> T::Value<'tcx>
|
||||||
where
|
where
|
||||||
T::Value<'tcx>: Decodable<DecodeContext<'a, 'tcx>>,
|
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> {
|
impl<T: ParameterizedOverTcx> LazyArray<T> {
|
||||||
|
#[inline]
|
||||||
fn decode<'a, 'tcx, M: Metadata<'a, 'tcx>>(
|
fn decode<'a, 'tcx, M: Metadata<'a, 'tcx>>(
|
||||||
self,
|
self,
|
||||||
metadata: M,
|
metadata: M,
|
||||||
@ -420,6 +422,7 @@ impl<'a, 'tcx> TyDecoder for DecodeContext<'a, 'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'tcx> Decodable<DecodeContext<'a, 'tcx>> for CrateNum {
|
impl<'a, 'tcx> Decodable<DecodeContext<'a, 'tcx>> for CrateNum {
|
||||||
|
#[inline]
|
||||||
fn decode(d: &mut DecodeContext<'a, 'tcx>) -> CrateNum {
|
fn decode(d: &mut DecodeContext<'a, 'tcx>) -> CrateNum {
|
||||||
let cnum = CrateNum::from_u32(d.read_u32());
|
let cnum = CrateNum::from_u32(d.read_u32());
|
||||||
d.map_encoded_cnum_to_current(cnum)
|
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 {
|
impl<'a, 'tcx> Decodable<DecodeContext<'a, 'tcx>> for DefIndex {
|
||||||
|
#[inline]
|
||||||
fn decode(d: &mut DecodeContext<'a, 'tcx>) -> DefIndex {
|
fn decode(d: &mut DecodeContext<'a, 'tcx>) -> DefIndex {
|
||||||
DefIndex::from_u32(d.read_u32())
|
DefIndex::from_u32(d.read_u32())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'tcx> Decodable<DecodeContext<'a, 'tcx>> for ExpnIndex {
|
impl<'a, 'tcx> Decodable<DecodeContext<'a, 'tcx>> for ExpnIndex {
|
||||||
|
#[inline]
|
||||||
fn decode(d: &mut DecodeContext<'a, 'tcx>) -> ExpnIndex {
|
fn decode(d: &mut DecodeContext<'a, 'tcx>) -> ExpnIndex {
|
||||||
ExpnIndex::from_u32(d.read_u32())
|
ExpnIndex::from_u32(d.read_u32())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'tcx> Decodable<DecodeContext<'a, 'tcx>> for ast::AttrId {
|
impl<'a, 'tcx> Decodable<DecodeContext<'a, 'tcx>> for ast::AttrId {
|
||||||
|
#[inline]
|
||||||
fn decode(d: &mut DecodeContext<'a, 'tcx>) -> ast::AttrId {
|
fn decode(d: &mut DecodeContext<'a, 'tcx>) -> ast::AttrId {
|
||||||
let sess = d.sess.expect("can't decode AttrId without Session");
|
let sess = d.sess.expect("can't decode AttrId without Session");
|
||||||
sess.parse_sess.attr_id_generator.mk_attr_id()
|
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> {
|
impl<'a, 'tcx, T> Decodable<DecodeContext<'a, 'tcx>> for LazyArray<T> {
|
||||||
|
#[inline]
|
||||||
fn decode(decoder: &mut DecodeContext<'a, 'tcx>) -> Self {
|
fn decode(decoder: &mut DecodeContext<'a, 'tcx>) -> Self {
|
||||||
let len = decoder.read_usize();
|
let len = decoder.read_usize();
|
||||||
if len == 0 { LazyArray::default() } else { decoder.read_lazy_array(len) }
|
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]>,
|
for<'tcx> T::Value<'tcx>: FixedSizeEncoding<ByteArray = [u8; N]>,
|
||||||
{
|
{
|
||||||
/// Given the metadata, extract out the value at a particular index (if any).
|
/// 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> {
|
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);
|
trace!("LazyTable::lookup: index={:?} len={:?}", i, self.len);
|
||||||
|
|
||||||
@ -494,10 +493,14 @@ where
|
|||||||
let end = start + width;
|
let end = start + width;
|
||||||
let bytes = &metadata.blob()[start..end];
|
let bytes = &metadata.blob()[start..end];
|
||||||
|
|
||||||
|
if let Ok(fixed) = bytes.try_into() {
|
||||||
|
FixedSizeEncoding::from_bytes(fixed)
|
||||||
|
} else {
|
||||||
let mut fixed = [0u8; N];
|
let mut fixed = [0u8; N];
|
||||||
fixed[..width].copy_from_slice(bytes);
|
fixed[..width].copy_from_slice(bytes);
|
||||||
FixedSizeEncoding::from_bytes(&fixed)
|
FixedSizeEncoding::from_bytes(&fixed)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Size of the table in entries, including possible gaps.
|
/// Size of the table in entries, including possible gaps.
|
||||||
pub(super) fn size(&self) -> usize {
|
pub(super) fn size(&self) -> usize {
|
||||||
|
Loading…
Reference in New Issue
Block a user