3 ms·
> or even just skipping blank lines, hyper does things its own way. Ugh. IMO a bit benefit of Rust is that you can’t do wild-west-YOLO buffer twiddling without
by amluto 3y ago
> or even just skipping blank lines, hyper does things its own way.
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.rs 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.
- scns 3y ago> Seriously, it should not be hard to efficiently strip a prefix off a u8 slice in safe Rust. For example, split_first. That is a good idea for a contribution, no?
- andrewaylett 3y agoYou mean like this one? https://github.com/seanmonstar/httparse/pull/86/files#diff-4bc73dd48e6ccc80311431323609ad12765c3635b53eebe2deaa4be10ecd9be6R53-R54 https://github.com/seanmonstar/httparse/pull/86/files#diff-4...
- andrewaylett 3y agoFollow 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. I raised a PR to fix the benchmarks: https://github.com/seanmonstar/httparse/pull/151 https://github.com/seanmonstar/httparse/pull/151
- LegionMammal978 3y agoThese 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.