Inline with_interner
This commit is contained in:
parent
05c09cb62d
commit
0ad8981945
1 changed files with 5 additions and 9 deletions
|
@ -1624,14 +1624,15 @@ impl Symbol {
|
||||||
|
|
||||||
/// Maps a string to its interned representation.
|
/// Maps a string to its interned representation.
|
||||||
pub fn intern(string: &str) -> Self {
|
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
|
/// Convert to a `SymbolStr`. This is a slowish operation because it
|
||||||
/// requires locking the symbol interner.
|
/// requires locking the symbol interner.
|
||||||
pub fn as_str(self) -> SymbolStr {
|
pub fn as_str(self) -> SymbolStr {
|
||||||
with_interner(|interner| unsafe {
|
with_session_globals(|session_globals| {
|
||||||
SymbolStr { string: std::mem::transmute::<&str, &str>(interner.get(self)) }
|
let symbol_str = session_globals.symbol_interner.get(self);
|
||||||
|
unsafe { SymbolStr { string: std::mem::transmute::<&str, &str>(symbol_str) } }
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1640,7 +1641,7 @@ impl Symbol {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn len(self) -> usize {
|
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 {
|
pub fn is_empty(self) -> bool {
|
||||||
|
@ -1879,11 +1880,6 @@ impl Ident {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[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
|
/// An alternative to [`Symbol`], useful when the chars within the symbol need to
|
||||||
/// be accessed. It deliberately has limited functionality and should only be
|
/// be accessed. It deliberately has limited functionality and should only be
|
||||||
/// used for temporary values.
|
/// used for temporary values.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue