Skip to content

Commit

Permalink
Improves trait map cloning performance.
Browse files Browse the repository at this point in the history
  • Loading branch information
esdrubal committed Aug 27, 2024
1 parent 99d1f5b commit 880cc3b
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions sway-core/src/semantic_analysis/namespace/trait_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ struct TraitEntry {
}

/// Map of trait name and type to [TraitItems].
type TraitImpls = Vec<TraitEntry>;
type TraitImpls = im::Vector<TraitEntry>;

/// Map holding trait implementations for types.
///
Expand All @@ -136,7 +136,7 @@ type TraitImpls = Vec<TraitEntry>;
#[derive(Clone, Debug, Default)]
pub(crate) struct TraitMap {
trait_impls: TraitImpls,
satisfied_cache: hashbrown::HashSet<u64>,
satisfied_cache: im::HashSet<u64>,
}

pub(crate) enum IsImplSelf {
Expand Down Expand Up @@ -413,10 +413,11 @@ impl TraitMap {
impl_span,
};
let entry = TraitEntry { key, value };
let trait_impls: TraitImpls = vec![entry];
let mut trait_impls: TraitImpls = im::Vector::new();
trait_impls.push_back(entry);
let trait_map = TraitMap {
trait_impls,
satisfied_cache: HashSet::default(),
satisfied_cache: im::HashSet::default(),
};

self.extend(trait_map, engines);
Expand Down Expand Up @@ -549,7 +550,7 @@ impl TraitMap {
.as_ref()
.map_or(false, |span| span == &trait_decl_span)
{
trait_map.trait_impls.push(entry.clone());
trait_map.trait_impls.push_back(entry.clone());
}
}
trait_map
Expand Down

0 comments on commit 880cc3b

Please sign in to comment.