Skip to content

Slow suggestion of single_char_pattern #3813

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
CryZe opened this issue Feb 24, 2019 · 3 comments
Closed

Slow suggestion of single_char_pattern #3813

CryZe opened this issue Feb 24, 2019 · 3 comments
Labels
L-perf Lint: Belongs in the perf lint group

Comments

@CryZe
Copy link

CryZe commented Feb 24, 2019

For str::starts_with using a single char string literal generates much better code as it can just compare the single byte of the str literal, while comparing against a char involves decoding possibly multiple bytes of the text. Here is the Godbolt for it: https://rust.godbolt.org/z/V_Arel

Therefore the single_char_pattern lint should not apply for str::starts_with (and possibly ends_with) and instead it should possibly even advice against using a char.

clippy 0.0.212 (b2601be 2018-11-27)

@oli-obk oli-obk added the L-perf Lint: Belongs in the perf lint group label Feb 25, 2019
@kennytm
Copy link
Member

kennytm commented Feb 25, 2019

Previously: rust-lang/rust#41993

I'd oppose reversing this lint though, it is just an implementation defect and can be fixed.

@ebroto
Copy link
Member

ebroto commented Aug 14, 2020

I think this can be closed now according to the resolution of the linked issue. See also rust-lang/rust#67249 and rust-lang/rust#69481.

@CryZe CryZe closed this as completed Aug 14, 2020
@CryZe
Copy link
Author

CryZe commented Aug 14, 2020

For non-ASCII it still seems to be slightly slower, but yeah, I'd say it's fine to recommend char now.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
L-perf Lint: Belongs in the perf lint group
Projects
None yet
Development

No branches or pull requests

4 participants