@@ -6,6 +6,7 @@ use std::{
66 ops:: { Deref , DerefMut } ,
77} ;
88
9+ use indexmap:: map:: RawEntryApiV1 ;
910use once_cell:: sync:: Lazy ;
1011use phf:: phf_set;
1112use rustc_hash:: FxHashSet ;
@@ -545,28 +546,41 @@ impl IdIdx {
545546
546547#[ derive( Default ) ]
547548pub struct Ids {
548- map : hashbrown :: HashMap < Id , IdIdx , rustc_hash:: FxBuildHasher > ,
549+ map : indexmap :: IndexMap < Id , ( ) , rustc_hash:: FxBuildHasher > ,
549550}
550551
551552impl Ids {
553+ #[ inline( always) ]
554+ pub fn intern_ident ( & mut self , ident : & Ident ) -> IdIdx {
555+ self . intern ( & ident. sym , ident. ctxt )
556+ }
557+
552558 pub fn intern ( & mut self , atom : & Atom , ctxt : SyntaxContext ) -> IdIdx {
553559 let mut hasher = rustc_hash:: FxHasher :: default ( ) ;
554560 atom. hash ( & mut hasher) ;
555561 ctxt. hash ( & mut hasher) ;
556562 let hash = hasher. finish ( ) ;
557563
558- let len = self . map . len ( ) ;
559-
560- let ( _, idx) = self
564+ use indexmap:: map:: raw_entry_v1:: RawEntryMut :: * ;
565+ let idx = match self
561566 . map
562- . raw_entry_mut ( )
567+ . raw_entry_mut_v1 ( )
563568 . from_hash ( hash, |id| id. 1 == ctxt && id. 0 . eq ( atom) )
564- . or_insert_with ( || {
565- let idx = IdIdx ( len as u32 ) ;
569+ {
570+ Occupied ( occ) => occ. index ( ) ,
571+ Vacant ( vac) => {
566572 let id = ( atom. clone ( ) , ctxt) ;
567- ( id, idx)
568- } ) ;
569- * idx
573+ let idx = vac. index ( ) ;
574+ vac. insert_hashed_nocheck ( hash, id, ( ) ) ;
575+ idx
576+ }
577+ } ;
578+ IdIdx ( idx as u32 )
579+ }
580+
581+ #[ inline( always) ]
582+ pub fn get ( & self , idx : IdIdx ) -> & Id {
583+ & self . map . get_index ( idx. 0 as usize ) . unwrap ( ) . 0
570584 }
571585}
572586
0 commit comments