Skip to content

Commit

Permalink
Inline with_interner
Browse files Browse the repository at this point in the history
  • Loading branch information
bjorn3 committed Sep 15, 2021
1 parent 05c09cb commit 0ad8981
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions compiler/rustc_span/src/symbol.rs
Expand Up @@ -1624,14 +1624,15 @@ impl Symbol {

/// 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) } }
})
}

Expand All @@ -1640,7 +1641,7 @@ impl Symbol {
}

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 {
Expand Down Expand Up @@ -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
/// be accessed. It deliberately has limited functionality and should only be
/// used for temporary values.
Expand Down

0 comments on commit 0ad8981

Please sign in to comment.