#[cfg(test)]
use std::cell::Cell;
#[cfg(test)]
thread_local! {
static DONE: Cell<u64> = const { Cell::new(0) };
}
#[inline(always)]
pub(crate) fn done(units: usize) {
#[cfg(test)]
DONE.with(|done| done.set(done.get().saturating_add(units as u64)));
#[cfg(not(test))]
let _ = units;
}
#[inline(always)]
pub(crate) fn searched(haystack: usize, found: Option<usize>, needle: usize) {
done(found.map_or(haystack, |at| (at + needle).min(haystack)));
}
#[cfg(test)]
pub(crate) fn counted<T>(run: impl FnOnce() -> T) -> (T, u64) {
let before = DONE.with(Cell::get);
let value = run();
(value, DONE.with(Cell::get) - before)
}