rust-lang / rust-lang/rust-clippy
map + pow to successor + mul
Open
Nobody has claimed this yet.
A-lint
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
What it does
Use successor instead of map of pow to calculate pow, etc.
Lint Name
map_pow_to_successor
Category
perf
Advantage
- better perf, origin: $O(n * \log(n))$ , if use exponentiating by squaring. Now: $O(n)$
Drawbacks
Longer code.
Example
fn foo(y: u32) -> Vec<u32> {
(0..).map(|i| y.pow(i)).take(5).collect()
}
fn main() {
println!("{:?}", foo(7));
}
Could be written as:
use std::iter::successors;
fn foo(y: u32) -> Vec<u32> {
successors(Some(1), |x| Some(y * x)).take(5).collect()
}
fn main() {
println!("{:?}", foo(7));
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the issue's Rust examples and the proposed lint name, map_pow_to_successor; the payload does not identify an implementation file, test, or entry point. Done means adding this performance lint so the shown map of pow pattern is recognized and the successor-based alternative is covered by tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100