#![cfg(feature = "dhat-heap")]
use std::hint::black_box;
use xocomil::pct::{self, Mode};
#[global_allocator]
static ALLOC: dhat::Alloc = dhat::Alloc;
#[test]
fn pct_hot_paths_zero_alloc() {
let _profiler = dhat::Profiler::builder().testing().build();
let baseline = dhat::HeapStats::get();
let clean = b"/api/v1/users/12345/orders";
let mut out = [0u8; 64];
for _ in 0..1000 {
let r = pct::decode(black_box(clean), Mode::Path, &mut out).unwrap();
black_box(r);
}
let with_escapes = b"/users/foo%20bar/items/baz%2Fqux";
for _ in 0..1000 {
let r = pct::decode(black_box(with_escapes), Mode::Path, &mut out).unwrap();
black_box(r);
}
let form = b"hello+world%21+from+rust";
for _ in 0..1000 {
let r = pct::decode(black_box(form), Mode::Form, &mut out).unwrap();
black_box(r);
}
let stats = dhat::HeapStats::get();
dhat::assert_eq!(stats.total_blocks - baseline.total_blocks, 0);
dhat::assert_eq!(stats.total_bytes - baseline.total_bytes, 0);
}