News for hackers. Stuff that matters.
Re:Unsafe at Any Speed: Tradeoffs and Values in the Rust Eco... by amluto on Thursday January 25, 2024 @07:07PM (#39137229)
> 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...

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.

Re:Unsafe at Any Speed: Tradeoffs and Values in the Rust Eco... by LegionMammal978 on Thursday January 25, 2024 @07:36PM (#39137474)
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.
Re:Unsafe at Any Speed: Tradeoffs and Values in the Rust Eco... by scns on Thursday January 25, 2024 @08:39PM (#39137945)
> 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?

Re:Unsafe at Any Speed: Tradeoffs and Values in the Rust Eco... by andrewaylett on Friday January 26, 2024 @05:21AM (#39140958)
Re:Unsafe at Any Speed: Tradeoffs and Values in the Rust Eco... by andrewaylett on Friday January 26, 2024 @02:11PM (#39146702)
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.

I raised a PR to fix the benchmarks: https://github.com/seanmonstar/httparse/pull/151