mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 11:20:54 +00:00
Switch AstIdMap
to hashbrown::HashTable
from the raw API
It's the intended use.
This commit is contained in:
parent
4d95ae52f8
commit
f44e01e3d0
@ -132,7 +132,7 @@ pub struct AstIdMap {
|
||||
/// Maps stable id to unstable ptr.
|
||||
arena: Arena<SyntaxNodePtr>,
|
||||
/// Reverse: map ptr to id.
|
||||
map: hashbrown::HashMap<Idx<SyntaxNodePtr>, (), ()>,
|
||||
map: hashbrown::HashTable<Idx<SyntaxNodePtr>>,
|
||||
}
|
||||
|
||||
impl fmt::Debug for AstIdMap {
|
||||
@ -169,13 +169,13 @@ impl AstIdMap {
|
||||
TreeOrder::DepthFirst
|
||||
}
|
||||
});
|
||||
res.map = hashbrown::HashMap::with_capacity_and_hasher(res.arena.len(), ());
|
||||
res.map = hashbrown::HashTable::with_capacity(res.arena.len());
|
||||
for (idx, ptr) in res.arena.iter() {
|
||||
let hash = hash_ptr(ptr);
|
||||
match res.map.raw_entry_mut().from_hash(hash, |idx2| *idx2 == idx) {
|
||||
hashbrown::hash_map::RawEntryMut::Occupied(_) => unreachable!(),
|
||||
hashbrown::hash_map::RawEntryMut::Vacant(entry) => {
|
||||
entry.insert_with_hasher(hash, idx, (), |&idx| hash_ptr(&res.arena[idx]));
|
||||
match res.map.entry(hash, |&idx2| idx2 == idx, |&idx| hash_ptr(&res.arena[idx])) {
|
||||
hashbrown::hash_table::Entry::Occupied(_) => unreachable!(),
|
||||
hashbrown::hash_table::Entry::Vacant(entry) => {
|
||||
entry.insert(idx);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -196,8 +196,8 @@ impl AstIdMap {
|
||||
pub fn ast_id_for_ptr<N: AstIdNode>(&self, ptr: AstPtr<N>) -> FileAstId<N> {
|
||||
let ptr = ptr.syntax_node_ptr();
|
||||
let hash = hash_ptr(&ptr);
|
||||
match self.map.raw_entry().from_hash(hash, |&idx| self.arena[idx] == ptr) {
|
||||
Some((&raw, &())) => FileAstId {
|
||||
match self.map.find(hash, |&idx| self.arena[idx] == ptr) {
|
||||
Some(&raw) => FileAstId {
|
||||
raw: ErasedFileAstId(raw.into_raw().into_u32()),
|
||||
covariant: PhantomData,
|
||||
},
|
||||
@ -221,8 +221,8 @@ impl AstIdMap {
|
||||
fn erased_ast_id(&self, item: &SyntaxNode) -> ErasedFileAstId {
|
||||
let ptr = SyntaxNodePtr::new(item);
|
||||
let hash = hash_ptr(&ptr);
|
||||
match self.map.raw_entry().from_hash(hash, |&idx| self.arena[idx] == ptr) {
|
||||
Some((&idx, &())) => ErasedFileAstId(idx.into_raw().into_u32()),
|
||||
match self.map.find(hash, |&idx| self.arena[idx] == ptr) {
|
||||
Some(&idx) => ErasedFileAstId(idx.into_raw().into_u32()),
|
||||
None => panic!(
|
||||
"Can't find {:?} in AstIdMap:\n{:?}\n source text: {}",
|
||||
item,
|
||||
|
Loading…
x
Reference in New Issue
Block a user