Skip to content

Commit

Permalink
tiny perf gain (FuelLabs#1676)
Browse files Browse the repository at this point in the history
  • Loading branch information
sezna authored May 26, 2022
1 parent ab4a505 commit a3b9cee
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions sway-core/src/semantic_analysis/namespace/trait_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ impl TraitMap {

pub(crate) fn get_methods_for_type(&self, r#type: TypeInfo) -> Vec<TypedFunctionDeclaration> {
let mut methods = vec![];
// small performance gain in bad case
if r#type == TypeInfo::ErrorRecovery {
return methods;
}
for ((_, type_info), l_methods) in self.trait_map.iter() {
if *type_info == r#type {
methods.append(&mut l_methods.values().cloned().collect());
Expand All @@ -102,6 +106,10 @@ impl TraitMap {
r#type: TypeInfo,
) -> HashMap<TraitName, Vec<TypedFunctionDeclaration>> {
let mut methods: HashMap<TraitName, Vec<TypedFunctionDeclaration>> = HashMap::new();
// small performance gain in bad case
if r#type == TypeInfo::ErrorRecovery {
return methods;
}
for ((trait_name, type_info), trait_methods) in self.trait_map.iter() {
if *type_info == r#type {
methods.insert(
Expand Down

0 comments on commit a3b9cee

Please sign in to comment.