Skip to content

Commit

Permalink
refactor(semantic): SymbolTable::set_name return old name (#7869)
Browse files Browse the repository at this point in the history
`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.
  • Loading branch information
overlookmotel committed Dec 14, 2024
1 parent 85dcf39 commit 2fdf988
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions crates/oxc_semantic/src/symbol.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::mem;

#[cfg(feature = "serialize")]
use serde::Serialize;
#[cfg(feature = "serialize")]
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 2fdf988

Please sign in to comment.