-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Labels
A-lintArea: New lintsArea: New lintsL-perfLint: Belongs in the perf lint groupLint: Belongs in the perf lint groupT-middleType: Probably requires verifiying typesType: Probably requires verifiying typesgood first issueThese issues are a good way to get started with ClippyThese issues are a good way to get started with Clippy
Description
What it does
Checks for consecutive calls to str::replace
(2 or more) that can be collapsed into a single call.
Categories (optional)
- Kind: perf
What is the advantage of the recommended code over the original code
Faster since the string is only scanned once. Also less repetitive code.
Drawbacks
None.
Example
"hesuo worpd"
.replace('s', "l")
.replace("u", "l")
.replace('p', "l")
Could be written as:
"hesuo worpd".replace(|c| matches!(c, 's' | 'u' | 'p'), "l")
Using matches!
is potentially faster than a slice of chars (replace(&['s', 'u', 'p'], "l")
). But if any of the chars are variables, the lint can fall back to suggesting a slice of chars.
Metadata
Metadata
Assignees
Labels
A-lintArea: New lintsArea: New lintsL-perfLint: Belongs in the perf lint groupLint: Belongs in the perf lint groupT-middleType: Probably requires verifiying typesType: Probably requires verifiying typesgood first issueThese issues are a good way to get started with ClippyThese issues are a good way to get started with Clippy