use a SmallVec in impl_or_trait_item

This commit is contained in:
lcnr 2021-04-06 17:06:44 +02:00
parent e1d49aaad4
commit b729815fc7

View File

@ -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()