1
Fork 0

Optimize Symbol::integer by utilizing itoa in-place formatting

This commit is contained in:
Urgau 2024-03-06 19:39:36 +01:00
parent 1547c076bf
commit 33ef4b963b
3 changed files with 6 additions and 2 deletions

View file

@ -2325,13 +2325,15 @@ pub mod sym {
///
/// The first few non-negative integers each have a static symbol and therefore
/// are fast.
pub fn integer<N: TryInto<usize> + Copy + ToString>(n: N) -> Symbol {
pub fn integer<N: TryInto<usize> + Copy + itoa::Integer>(n: N) -> Symbol {
if let Result::Ok(idx) = n.try_into() {
if idx < 10 {
return Symbol::new(super::SYMBOL_DIGITS_BASE + idx as u32);
}
}
Symbol::intern(&n.to_string())
let mut buffer = itoa::Buffer::new();
let printed = buffer.format(n);
Symbol::intern(printed)
}
}