Skip to content

Commit b01026d

Browse files
committed
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
2 parents 1c158b6 + b729815 commit b01026d

File tree

1 file changed

+4
-2
lines changed
  • compiler/rustc_typeck/src/check/method

1 file changed

+4
-2
lines changed

compiler/rustc_typeck/src/check/method/probe.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1768,7 +1768,9 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
17681768

17691769
/// Finds the method with the appropriate name (or return type, as the case may be). If
17701770
/// `allow_similar_names` is set, find methods with close-matching names.
1771-
fn impl_or_trait_item(&self, def_id: DefId) -> Vec<ty::AssocItem> {
1771+
// The length of the returned iterator is nearly always 0 or 1 and this
1772+
// method is fairly hot.
1773+
fn impl_or_trait_item(&self, def_id: DefId) -> SmallVec<[ty::AssocItem; 1]> {
17721774
if let Some(name) = self.method_name {
17731775
if self.allow_similar_names {
17741776
let max_dist = max(name.as_str().len(), 3) / 3;
@@ -1784,7 +1786,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
17841786
} else {
17851787
self.fcx
17861788
.associated_item(def_id, name, Namespace::ValueNS)
1787-
.map_or_else(Vec::new, |x| vec![x])
1789+
.map_or_else(SmallVec::new, |x| SmallVec::from_buf([x]))
17881790
}
17891791
} else {
17901792
self.tcx.associated_items(def_id).in_definition_order().copied().collect()

0 commit comments

Comments
 (0)