We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
.cloned().filter()
In an iterator chain, .cloned().filter() will lead to cloning items that are filtered out. This is wasteful and should be the other way around.
Improves performance by cloning less.
None to my knowledge.
fn process_items<'a>(items: impl Iterator<Item = &Item>) -> ProcessedItems { items.cloned().filter(filter_item).map(process_item).collect() }
Could be written as:
fn process_items<'a>(items: impl Iterator<Item = &Item>) -> ProcessedItems { items.filter(filter_item).cloned().map(process_item).collect() }
The text was updated successfully, but these errors were encountered:
Note: This is split from #3302
Sorry, something went wrong.
This lint already exists: https://rust-lang.github.io/rust-clippy/master/index.html#iter_overeager_cloned
warning: unnecessarily eager cloning of iterator items --> src/lib.rs:8:5 | 8 | items.cloned().filter(filter_item).map(process_item).collect() | ^^^^^----------------------------- | | | help: try: `.filter(|&x| filter_item(x)).cloned()` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#iter_overeager_cloned = note: `#[warn(clippy::iter_overeager_cloned)]` on by default
Got it.
No branches or pull requests
What it does
In an iterator chain,
.cloned().filter()
will lead to cloning items that are filtered out. This is wasteful and should be the other way around.Advantage
Improves performance by cloning less.
Drawbacks
None to my knowledge.
Example
Could be written as:
The text was updated successfully, but these errors were encountered: