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 80e1d2d
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions sway-core/src/semantic_analysis/namespace/trait_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use std::{
sync::Arc,
};

use hashbrown::HashSet;
use sway_error::{
error::CompileError,
handler::{ErrorEmitted, Handler},
Expand Down Expand Up @@ -127,7 +126,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 +135,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 +412,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 +549,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 80e1d2d

Please sign in to comment.