3 ms·
std::str::from_bytes is that API. Rust’s current implementation of full validation: https://github.com/rust-lang/rust/blob/2a3f5367a23a769a068c37460db336de427c
by chrismorgan 9y ago
std::str::from_bytes is that API.
Rust’s current implementation of full validation: https://github.com/rust-lang/rust/blob/2a3f5367a23a769a068c37460db336de427c4b48/src/libcore/str/mod.rs#L1458-L1578 https://github.com/rust-lang/rust/blob/2a3f5367a23a769a068c3...
I have a vague feeling there’s an even faster path for probably-ASCII out there, but I can’t immediately recall where and am going to bed. Doubtless someone else will answer before I get up.
The core team will be amenable to replacing this algorithm with something faster presuming it’s still correct.
- kzrdude 9y agoGiven the new simd features, it's probably time to revisit that now
- MichaelGG 9y agoThere is probably a trade-off depending on the content of the string, right? So the API probably needs a general-purpose and a "this should be all ASCII" version?
- simias 9y agoI don't know if it really makes a lot of sense to have such a specialized version of a method in the standard library. Effectively from_str and from_str_mostlyascii would be functionally identical except for a small performance difference depending on the encoding of the string data which wouldn't matter in 99% of programs. Having that as a 3rd party crate would make complete sense however.
- Retra 9y agoIf there's a canonical, obvious, and low maintenance way to do something that there's a common need for, then there's no reason it shouldn't be in std. If it needs to be hacked at and redesigned every few years, then yeah, leave it out.
- simias 9y agoThat's not really the Rust way, for instance things like timekeeping and random number generation are delegated to external crates. Given how trivial it is to add dependencies thanks to cargo it's not really an issue in practice, even if I do think that they go a bit overboard at times (time really ought to be in std IMO, especially since there's already a rather useless std::time module).