5
5
//! type, and vice versa.
6
6
7
7
use rustc_arena:: DroplessArena ;
8
- use rustc_data_structures:: fx:: FxHashMap ;
8
+ use rustc_data_structures:: fx:: { FxHashMap , FxHasher } ;
9
9
use rustc_data_structures:: stable_hasher:: { HashStable , StableHasher , ToStableHashKey } ;
10
10
use rustc_macros:: HashStable_Generic ;
11
11
use rustc_serialize:: { Decodable , Decoder , Encodable , Encoder } ;
@@ -5051,17 +5051,26 @@ rustc_index::newtype_index! {
5051
5051
pub struct SymbolIndex { .. }
5052
5052
}
5053
5053
5054
+ fn fx_hash ( string : & str ) -> u64 {
5055
+ let mut hasher = FxHasher :: default ( ) ;
5056
+ string. hash ( & mut hasher) ;
5057
+ hasher. finish ( )
5058
+ }
5059
+
5054
5060
impl Symbol {
5055
5061
const fn new ( n : u32 ) -> Self {
5056
5062
Symbol ( SymbolIndex :: from_u32 ( n) )
5057
5063
}
5058
5064
5059
5065
/// Maps a string to its interned representation.
5060
5066
pub fn intern ( string : & str ) -> Self {
5061
- if let Some ( symbol) = unsafe { STATIC_SYMBOLS . get ( string) } {
5067
+ let hash = fx_hash ( string) ;
5068
+ if let Some ( ( _, symbol) ) =
5069
+ unsafe { & STATIC_SYMBOLS } . raw_entry ( ) . from_key_hashed_nocheck ( hash, string)
5070
+ {
5062
5071
* symbol
5063
5072
} else {
5064
- with_interner ( |interner| interner. intern ( string) )
5073
+ with_interner ( |interner| interner. intern_ext ( hash , string) )
5065
5074
}
5066
5075
}
5067
5076
@@ -5163,8 +5172,8 @@ impl Interner {
5163
5172
}
5164
5173
5165
5174
#[ inline]
5166
- pub fn intern ( & mut self , string : & str ) -> Symbol {
5167
- if let Some ( & name) = self . names . get ( string) {
5175
+ fn intern_ext ( & mut self , hash : u64 , string : & str ) -> Symbol {
5176
+ if let Some ( ( _ , & name) ) = self . names . raw_entry ( ) . from_key_hashed_nocheck ( hash , string) {
5168
5177
return name;
5169
5178
}
5170
5179
@@ -5182,6 +5191,11 @@ impl Interner {
5182
5191
name
5183
5192
}
5184
5193
5194
+ #[ inline]
5195
+ pub fn intern ( & mut self , string : & str ) -> Symbol {
5196
+ self . intern_ext ( fx_hash ( string) , string)
5197
+ }
5198
+
5185
5199
// Get the symbol as a string. `Symbol::as_str()` should be used in
5186
5200
// preference to this function.
5187
5201
pub fn get ( & self , symbol : Symbol ) -> & str {
0 commit comments