xocomil 0.3.0

A lightweight, zero-allocation HTTP/1.1 request parser and response writer
Documentation
//! Heap-allocation audit for `xocomil::query`.
//!
//! Run with: `cargo test --release --features dhat-heap --test alloc_query`
//!
//! See `alloc_pct.rs` for the design rationale (one test per binary,
//! delta-based assertions).

#![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();

    // -- Plain iteration ------------------------------------------------
    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);
        }
    }

    // -- Iteration + form-decode (the realistic extractor path) --------
    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);
}