These days, stripping fixed-length prefixes and suffixes off of slices is pretty easy with slice patterns. But that code was originally written around the time of Rust 1.0.0, when the language and standard library had far fewer features to help with this. For instance, it uses slice::from_raw_parts() rather than slice.get_unchecked(pos..), since the latter wasn't stable until Rust 1.15.0. Similarly, split_first() wasn't stable until Rust 1.5.0, and slice patterns weren't stable until Rust 1.26.0.
Follow up -- the benchmarks on that PR look poor, but the benchmarks don't actually quite measure what they're expected to measure -- they're not black-boxing inputs, so the compiler has an opportunity to constant-fold in some cases.
Ugh. IMO a bit benefit of Rust is that you can’t do wild-west-YOLO buffer twiddling without “unsafe,” so people will write better code.
But it really looks like httparse missed the memo.
https://github.com/seanmonstar/httparse/blob/v1.8.0/src/iter...
iter::Bytes looks like an awkward wrapper around slices with all the safety removed. So you can port nasty C-style code right over.
Seriously, it should not be hard to efficiently strip a prefix off a u8 slice in safe Rust. For example, split_first.