#![cfg(feature = "dhat-heap")]
use std::hint::black_box;
use xocomil::pct::{self, Mode};
use xocomil::query;
#[global_allocator]
static ALLOC: dhat::Alloc = dhat::Alloc;
#[test]
fn query_hot_paths_zero_alloc() {
let _profiler = dhat::Profiler::builder().testing().build();
let baseline = dhat::HeapStats::get();
let plain = b"q=hello+world&page=2&limit=20&sort=desc&filter=active";
for _ in 0..1000 {
for pair in query::parse(black_box(plain)) {
black_box(pair);
}
}
let with_decode = b"q=hello+world&page=2&filter=active%20only";
let mut buf = [0u8; 64];
for _ in 0..1000 {
for (name, value) in query::parse(black_box(with_decode)) {
let _ = pct::decode(name, Mode::Form, &mut buf).unwrap();
let _ = pct::decode(value, Mode::Form, &mut buf).unwrap();
}
}
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);
}