Allow inlining of `array::map()`
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
Right now array::map() and array::try_map() do not allow inlining, which makes it not possible to use these convenience methods in performance-sensitive cases and requires writing much more verbose loops.
For example, this doesn't inline:
let lut = rs1.to_le_bytes();
let result = rs2.to_le_bytes().map(|idx| {
*lut.get(usize::from(idx)).unwrap_or(&0)
});
But this does:
let lut = rs1.to_le_bytes();
let mut result = [0; _];
for (&idx, r) in rs2.to_le_bytes().iter().zip(&mut result) {
*r = *lut.get(usize::from(idx)).unwrap_or(&0);
}
But the first option is much more natural.
Adding #[inline] on both array::map() and array::try_map() would really help here.
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
Locate the standard-library definitions of array::map() and array::try_map(), then inspect how their current implementations handle inlining. Add the requested inlining attributes to both methods and verify that the relevant standard-library checks pass and the methods can inline in performance-sensitive use cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- performance
- Issue type
- Feature
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 72/100