mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 04:08:41 +00:00
refactor(semantic): SymbolTable::set_name return old name (#7869)
`SymbolTable::set_name` return old symbol name. `set_name` is marked `#[inline]`, so where the caller does not use the old name, getting it should be optimized out by the compiler. So it makes the method more flexible, at no cost.
This commit is contained in:
parent
c0714945b2
commit
1cf8f8f2ca
1 changed files with 6 additions and 2 deletions
|
|
@ -1,3 +1,5 @@
|
|||
use std::mem;
|
||||
|
||||
#[cfg(feature = "serialize")]
|
||||
use serde::Serialize;
|
||||
#[cfg(feature = "serialize")]
|
||||
|
|
@ -101,9 +103,11 @@ impl SymbolTable {
|
|||
}
|
||||
|
||||
/// Rename a symbol.
|
||||
///
|
||||
/// Returns the old name.
|
||||
#[inline]
|
||||
pub fn set_name(&mut self, symbol_id: SymbolId, name: CompactStr) {
|
||||
self.names[symbol_id] = name;
|
||||
pub fn set_name(&mut self, symbol_id: SymbolId, name: CompactStr) -> CompactStr {
|
||||
mem::replace(&mut self.names[symbol_id], name)
|
||||
}
|
||||
|
||||
/// Get the [`SymbolFlags`] for a symbol, which describe how the symbol is declared.
|
||||
|
|
|
|||
Loading…
Reference in a new issue