Skip to content

Commit f1342df

Browse files
committed
Adds comment explaining why we use HashMap instead of OrdMap.
1 parent 4217bea commit f1342df

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

docs/internals.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,9 +316,9 @@ pub struct LexicalScope {
316316

317317
/// The set of items that exist within some lexical scope via declaration or importing.
318318
pub struct Items {
319-
/// An ordered map from `Ident`s to their associated parsed declarations.
319+
/// A map from `Ident`s to their associated parsed declarations.
320320
pub(crate) parsed_symbols: ParsedSymbolMap,
321-
/// An ordered map from `Ident`s to their associated typed declarations.
321+
/// A map from `Ident`s to their associated typed declarations.
322322
pub(crate) symbols: SymbolMap,
323323
...
324324
}

sway-core/src/semantic_analysis/namespace/lexical_scope.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ impl ResolvedFunctionDecl {
3636
}
3737
}
3838

39+
// The following types were using im::OrdMap but it revealed to be
40+
// much slower than using HashMap and sorting on iterationn.
3941
pub(super) type SymbolMap = HashMap<Ident, ResolvedDeclaration>;
4042
pub(super) type SymbolUniqueMap = HashMap<IdentUnique, ResolvedDeclaration>;
4143

@@ -82,10 +84,10 @@ pub struct LexicalScope {
8284
/// The set of items that exist within some lexical scope via declaration or importing.
8385
#[derive(Clone, Debug, Default)]
8486
pub struct Items {
85-
/// An ordered map from `Ident`s to their associated declarations.
87+
/// An map from `Ident`s to their associated declarations.
8688
pub(crate) symbols: SymbolMap,
8789

88-
/// An ordered map from `IdentUnique`s to their associated declarations.
90+
/// An map from `IdentUnique`s to their associated declarations.
8991
/// This uses an Arc<RwLock<SymbolUniqueMap>> so it is shared between all
9092
/// Items clones. This is intended so we can keep the symbols of previous
9193
/// lexical scopes while collecting_unifications scopes.

0 commit comments

Comments
 (0)