remove allocation in Symbol creation

This commit is contained in:
Folkert 2022-03-18 21:55:20 +01:00
parent 9cb6261a4d
commit 813b22a106
No known key found for this signature in database
GPG key ID: 1F17F6FFD112B97C
5 changed files with 43 additions and 17 deletions

View file

@ -634,9 +634,11 @@ impl IdentIds {
/// This is used, for example, during canonicalization of an Expr::Closure
/// to generate a unique symbol to refer to that closure.
pub fn gen_unique(&mut self) -> IdentId {
// TODO convert this directly from u32 into IdentStr,
// without allocating an extra string along the way like this.
let ident = self.next_generated_name.to_string().into();
use std::fmt::Write;
let mut temp: arrayvec::ArrayString<15> = arrayvec::ArrayString::new();
write!(temp, "{}", self.next_generated_name).unwrap();
let ident = Ident(IdentStr::from_array_string(temp));
self.next_generated_name += 1;