diff options
| author | bors <bors@rust-lang.org> | 2021-04-07 12:52:33 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2021-04-07 12:52:33 +0000 |
| commit | b01026de465d5a5ef51e32c1012c43927d2a111c (patch) | |
| tree | 9ac626132e4f7838b5654bea775c2e4607189fc4 | |
| parent | 1c158b6a8b440f826d952c3a8f42bdc3f77a5ac1 (diff) | |
| parent | b729815fc72bc08544c6d630cb0dacadfc6ccef3 (diff) | |
| download | rust-b01026de465d5a5ef51e32c1012c43927d2a111c.tar.gz rust-b01026de465d5a5ef51e32c1012c43927d2a111c.zip | |
Auto merge of #83932 - lcnr:probe-perf, r=estebank
use a `SmallVec` in `impl_or_trait_item` #83293 showed that this is fairly hot, slightly improves max-rss and cpu cycles, does not noticeably improve instruction counts
| -rw-r--r-- | compiler/rustc_typeck/src/check/method/probe.rs | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/compiler/rustc_typeck/src/check/method/probe.rs b/compiler/rustc_typeck/src/check/method/probe.rs index d83b74f4ce9..15342235d48 100644 --- a/compiler/rustc_typeck/src/check/method/probe.rs +++ b/compiler/rustc_typeck/src/check/method/probe.rs @@ -1768,7 +1768,9 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { /// Finds the method with the appropriate name (or return type, as the case may be). If /// `allow_similar_names` is set, find methods with close-matching names. - fn impl_or_trait_item(&self, def_id: DefId) -> Vec<ty::AssocItem> { + // The length of the returned iterator is nearly always 0 or 1 and this + // method is fairly hot. + fn impl_or_trait_item(&self, def_id: DefId) -> SmallVec<[ty::AssocItem; 1]> { if let Some(name) = self.method_name { if self.allow_similar_names { let max_dist = max(name.as_str().len(), 3) / 3; @@ -1784,7 +1786,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { } else { self.fcx .associated_item(def_id, name, Namespace::ValueNS) - .map_or_else(Vec::new, |x| vec![x]) + .map_or_else(SmallVec::new, |x| SmallVec::from_buf([x])) } } else { self.tcx.associated_items(def_id).in_definition_order().copied().collect() |
