forked from Orchid/orchid
Removed a copious amount of premature Rc-s
This commit is contained in:
@@ -2,22 +2,22 @@ use std::hash::Hash;
|
||||
|
||||
use hashbrown::{HashMap, HashSet};
|
||||
|
||||
use crate::interner::Sym;
|
||||
use crate::interner::Tok;
|
||||
|
||||
#[derive(Clone, Debug, Default)]
|
||||
pub struct AliasMap {
|
||||
pub targets: HashMap<Sym, Sym>,
|
||||
pub aliases: HashMap<Sym, HashSet<Sym>>,
|
||||
pub targets: HashMap<Vec<Tok<String>>, Vec<Tok<String>>>,
|
||||
pub aliases: HashMap<Vec<Tok<String>>, HashSet<Vec<Tok<String>>>>,
|
||||
}
|
||||
impl AliasMap {
|
||||
pub fn new() -> Self {
|
||||
Self::default()
|
||||
}
|
||||
|
||||
pub fn link(&mut self, alias: Sym, target: Sym) {
|
||||
let prev = self.targets.insert(alias, target);
|
||||
pub fn link(&mut self, alias: Vec<Tok<String>>, target: Vec<Tok<String>>) {
|
||||
let prev = self.targets.insert(alias.clone(), target.clone());
|
||||
debug_assert!(prev.is_none(), "Alias already has a target");
|
||||
multimap_entry(&mut self.aliases, &target).insert(alias);
|
||||
multimap_entry(&mut self.aliases, &target).insert(alias.clone());
|
||||
// Remove aliases of the alias
|
||||
if let Some(alts) = self.aliases.remove(&alias) {
|
||||
for alt in alts {
|
||||
@@ -26,17 +26,18 @@ impl AliasMap {
|
||||
self.aliases.get(&alt).map(HashSet::is_empty).unwrap_or(true),
|
||||
"Alias set of alias not empty"
|
||||
);
|
||||
let alt_target = self.targets.insert(alt.clone(), target.clone());
|
||||
debug_assert!(
|
||||
self.targets.insert(alt, target) == Some(alias),
|
||||
alt_target.as_ref() == Some(&alias),
|
||||
"Name not target of its own alias"
|
||||
);
|
||||
multimap_entry(&mut self.aliases, &target).insert(alt);
|
||||
multimap_entry(&mut self.aliases, &alias).insert(alt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn resolve(&self, alias: Sym) -> Option<Sym> {
|
||||
self.targets.get(&alias).copied()
|
||||
pub fn resolve(&self, alias: &[Tok<String>]) -> Option<&Vec<Tok<String>>> {
|
||||
self.targets.get(alias)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user