Inline with_interner
This commit is contained in:
parent
05c09cb62d
commit
0ad8981945
@ -1624,14 +1624,15 @@ const fn new(n: u32) -> Self {
|
||||
|
||||
/// Maps a string to its interned representation.
|
||||
pub fn intern(string: &str) -> Self {
|
||||
with_interner(|interner| interner.intern(string))
|
||||
with_session_globals(|session_globals| session_globals.symbol_interner.intern(string))
|
||||
}
|
||||
|
||||
/// Convert to a `SymbolStr`. This is a slowish operation because it
|
||||
/// requires locking the symbol interner.
|
||||
pub fn as_str(self) -> SymbolStr {
|
||||
with_interner(|interner| unsafe {
|
||||
SymbolStr { string: std::mem::transmute::<&str, &str>(interner.get(self)) }
|
||||
with_session_globals(|session_globals| {
|
||||
let symbol_str = session_globals.symbol_interner.get(self);
|
||||
unsafe { SymbolStr { string: std::mem::transmute::<&str, &str>(symbol_str) } }
|
||||
})
|
||||
}
|
||||
|
||||
@ -1640,7 +1641,7 @@ pub fn as_u32(self) -> u32 {
|
||||
}
|
||||
|
||||
pub fn len(self) -> usize {
|
||||
with_interner(|interner| interner.get(self).len())
|
||||
with_session_globals(|session_globals| session_globals.symbol_interner.get(self).len())
|
||||
}
|
||||
|
||||
pub fn is_empty(self) -> bool {
|
||||
@ -1879,11 +1880,6 @@ pub fn is_raw_guess(self) -> bool {
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn with_interner<T, F: FnOnce(&Interner) -> T>(f: F) -> T {
|
||||
with_session_globals(|session_globals| f(&session_globals.symbol_interner))
|
||||
}
|
||||
|
||||
/// An alternative to [`Symbol`], useful when the chars within the symbol need to
|
||||
/// be accessed. It deliberately has limited functionality and should only be
|
||||
/// used for temporary values.
|
||||
|
Loading…
Reference in New Issue
Block a user