|
pub fn add_top_level_symbol(&mut self, symbol_ref: SymbolRef) { |
|
let canonical_ref = self.symbols.par_canonical_ref_for(symbol_ref); |
|
let original_name: Cow<'_, Rstr> = |
|
Cow::Owned(self.symbols.get_original_name(canonical_ref).to_rstr()); |
|
|
|
match self.canonical_names.entry(canonical_ref) { |
|
std::collections::hash_map::Entry::Vacant(vacant) => { |
|
let mut count = 0; |
|
let mut candidate_name = original_name.clone(); |
|
while self.used_canonical_names.contains(&candidate_name) { |
|
count += 1; |
|
candidate_name = Cow::Owned(format!("{original_name}${count}").into()); |
|
} |
|
self.used_canonical_names.insert(candidate_name.clone()); |
|
vacant.insert(candidate_name.into_owned()); |
|
} |
|
std::collections::hash_map::Entry::Occupied(_) => { |
|
// The symbol is already renamed |
|
} |
|
} |
|
} |
The current algorithm counts from 0 and may end up with a huge number of allocations and hashes for candidate_name.
The challenge is to come up with the most efficient strategy for finding the new name.
One possible solution is to follow esbuild - the assigned new name is a new name on the scope
The original discussion is #365.
rolldown/crates/rolldown/src/utils/renamer.rs
Lines 36 to 56 in b8555ac
The current algorithm counts from 0 and may end up with a huge number of allocations and hashes for
candidate_name.The challenge is to come up with the most efficient strategy for finding the new name.
One possible solution is to follow esbuild - the assigned new name is a new name on the scope
The original discussion is #365.