use core::cell::Cell;
use std::thread_local;
thread_local! {
pub(crate) static COUNT: Cell<usize> = Cell::new(0);
}
#[inline]
pub unsafe fn set_count(count: usize) {
COUNT.with(|c| c.set(count));
}
#[inline]
pub fn get_count() -> usize {
COUNT.with(|c| c.get())
}
#[inline]
pub fn bump_count() {
COUNT.with(|c| {
let count = c.get();
c.set(count + 1);
})
}
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)]
pub struct Ident {
pub idx: usize,
pub len: usize,
}
impl Ident {
#[inline]
pub fn new(len: usize) -> Ident {
Ident {
idx: get_count(),
len,
}
}
#[inline]
pub fn new_bumped(len: usize) -> Ident {
let id = Ident {
idx: get_count(),
len,
};
bump_count();
id
}
}