From 2ff1fc9b81c0764eaa43faaa8985c3669759c814 Mon Sep 17 00:00:00 2001 From: Dylan MacKenzie Date: Sun, 12 Apr 2020 10:48:56 -0700 Subject: [PATCH] Add `#[inline]` declarations --- src/librustc_metadata/rmeta/encoder.rs | 1 + src/librustc_middle/mir/mod.rs | 8 ++++++++ src/librustc_middle/mir/predecessors.rs | 6 ++++++ src/librustc_middle/ty/query/on_disk_cache.rs | 1 + 4 files changed, 16 insertions(+) diff --git a/src/librustc_metadata/rmeta/encoder.rs b/src/librustc_metadata/rmeta/encoder.rs index 9c9869c8557..b56198724db 100644 --- a/src/librustc_metadata/rmeta/encoder.rs +++ b/src/librustc_metadata/rmeta/encoder.rs @@ -68,6 +68,7 @@ macro_rules! encoder_methods { impl<'tcx> Encoder for EncodeContext<'tcx> { type Error = ::Error; + #[inline] fn emit_unit(&mut self) -> Result<(), Self::Error> { Ok(()) } diff --git a/src/librustc_middle/mir/mod.rs b/src/librustc_middle/mir/mod.rs index 3295e48b7b4..ea3e59666d6 100644 --- a/src/librustc_middle/mir/mod.rs +++ b/src/librustc_middle/mir/mod.rs @@ -381,15 +381,18 @@ impl<'tcx> Body<'tcx> { } /// Returns the return type; it always return first element from `local_decls` array. + #[inline] pub fn return_ty(&self) -> Ty<'tcx> { self.local_decls[RETURN_PLACE].ty } /// Gets the location of the terminator for the given block. + #[inline] pub fn terminator_loc(&self, bb: BasicBlock) -> Location { Location { block: bb, statement_index: self[bb].statements.len() } } + #[inline] pub fn predecessors_for( &self, bb: BasicBlock, @@ -398,6 +401,7 @@ impl<'tcx> Body<'tcx> { MappedLockGuard::map(predecessors, |preds| &mut preds[bb]) } + #[inline] pub fn predecessors(&self) -> impl std::ops::Deref + '_ { self.predecessor_cache.compute(&self.basic_blocks) } @@ -2639,18 +2643,21 @@ impl<'tcx> graph::DirectedGraph for Body<'tcx> { } impl<'tcx> graph::WithNumNodes for Body<'tcx> { + #[inline] fn num_nodes(&self) -> usize { self.basic_blocks.len() } } impl<'tcx> graph::WithStartNode for Body<'tcx> { + #[inline] fn start_node(&self) -> Self::Node { START_BLOCK } } impl<'tcx> graph::WithSuccessors for Body<'tcx> { + #[inline] fn successors(&self, node: Self::Node) -> >::Iter { self.basic_blocks[node].terminator().successors().cloned() } @@ -2667,6 +2674,7 @@ impl graph::GraphPredecessors<'graph> for Body<'tcx> { } impl graph::WithPredecessors for Body<'tcx> { + #[inline] fn predecessors(&self, node: Self::Node) -> >::Iter { self.predecessors_for(node).clone().into_iter() } diff --git a/src/librustc_middle/mir/predecessors.rs b/src/librustc_middle/mir/predecessors.rs index 90cf1e3ce4e..629b5c2efb7 100644 --- a/src/librustc_middle/mir/predecessors.rs +++ b/src/librustc_middle/mir/predecessors.rs @@ -15,14 +15,17 @@ pub struct PredecessorCache { } impl PredecessorCache { + #[inline] pub fn new() -> Self { PredecessorCache { cache: Lock::new(None) } } + #[inline] pub fn invalidate(&mut self) { *self.cache.get_mut() = None; } + #[inline] pub fn compute( &self, basic_blocks: &IndexVec>, @@ -45,18 +48,21 @@ impl PredecessorCache { } impl serialize::Encodable for PredecessorCache { + #[inline] fn encode(&self, s: &mut S) -> Result<(), S::Error> { serialize::Encodable::encode(&(), s) } } impl serialize::Decodable for PredecessorCache { + #[inline] fn decode(d: &mut D) -> Result { serialize::Decodable::decode(d).map(|_v: ()| Self::new()) } } impl HashStable for PredecessorCache { + #[inline] fn hash_stable(&self, _: &mut CTX, _: &mut StableHasher) { // do nothing } diff --git a/src/librustc_middle/ty/query/on_disk_cache.rs b/src/librustc_middle/ty/query/on_disk_cache.rs index 8aecc0e698a..e9bb659d5c8 100644 --- a/src/librustc_middle/ty/query/on_disk_cache.rs +++ b/src/librustc_middle/ty/query/on_disk_cache.rs @@ -922,6 +922,7 @@ where { type Error = E::Error; + #[inline] fn emit_unit(&mut self) -> Result<(), Self::Error> { Ok(()) }