Skip to content

Commit

Permalink
Use OrdMap instead of HashMap and sorting.
Browse files Browse the repository at this point in the history
  • Loading branch information
esdrubal committed Jan 7, 2025
1 parent b728b91 commit 792e419
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 18 deletions.
5 changes: 3 additions & 2 deletions sway-core/src/semantic_analysis/namespace/lexical_scope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use crate::{

use super::{root::ResolvedDeclaration, TraitMap};

use im::OrdMap;
use parking_lot::RwLock;
use sway_error::{
error::{CompileError, ShadowingSource},
Expand All @@ -36,8 +37,8 @@ impl ResolvedFunctionDecl {
}
}

pub(super) type SymbolMap = HashMap<Ident, ResolvedDeclaration>;
pub(super) type SymbolUniqueMap = HashMap<IdentUnique, ResolvedDeclaration>;
pub(super) type SymbolMap = OrdMap<Ident, ResolvedDeclaration>;
pub(super) type SymbolUniqueMap = OrdMap<IdentUnique, ResolvedDeclaration>;

type SourceIdent = Ident;

Expand Down
18 changes: 2 additions & 16 deletions sway-core/src/semantic_analysis/namespace/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,29 +202,15 @@ impl Root {
};

// Collect all items declared in the source module
let mut symbols = src_mod
.root_items()
.symbols
.keys()
.clone()
.collect::<Vec<_>>();
symbols.sort();
for symbol in symbols {
for symbol in src_mod.root_items().symbols.keys() {
let decl = &src_mod.root_items().symbols[symbol];
if is_ancestor(src, dst) || decl.visibility(engines).is_public() {
decls_and_item_imports.push((symbol.clone(), decl.clone(), src.to_vec()));
}
}
// Collect those item-imported items that the source module reexports
// These live in the same namespace as local declarations, so no shadowing is possible
let mut symbols = src_mod
.root_items()
.use_item_synonyms
.keys()
.clone()
.collect::<Vec<_>>();
symbols.sort();
for symbol in symbols {
for symbol in src_mod.root_items().use_item_synonyms.keys() {
let (_, path, decl, src_visibility) = &src_mod.root_items().use_item_synonyms[symbol];
if src_visibility.is_public() {
decls_and_item_imports.push((symbol.clone(), decl.clone(), get_path(path.clone())))
Expand Down

0 comments on commit 792e419

Please sign in to comment.