2 ms·
Sure, and the code deals with that case. https://github.com/rust-lang/rust/blob/5cf55165fae5c8538db5c00e252ad9ba42aaf246/src/libcore/str/pattern.rs#L314-L340 h
by Manishearth 9y ago
Sure, and the code deals with that case.
https://github.com/rust-lang/rust/blob/5cf55165fae5c8538db5c00e252ad9ba42aaf246/src/libcore/str/pattern.rs#L314-L340 https://github.com/rust-lang/rust/blob/5cf55165fae5c8538db5c...
This does mean you have some somewhat pathological cases, but they're relatively rare because most strings come from only a couple unicode blocks, so all bytes other than the first will be from a really small set. A further optimization could be to fall back to the original find code if we realize we're hitting a pathological case.
(Also, FWIW, searching for an ASCII char can never cause this because of how UTF8's streaming property -- https://en.wikipedia.org/wiki/UTF-8#Description https://en.wikipedia.org/wiki/UTF-8#Description -- but given that we only search for the last byte, searching for a multibyte codepoint can lead to false positives with a shared last byte. We handle that.)