-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Implement array::repeat
#119127
New issue
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
Implement array::repeat
#119127
Conversation
As I wrote in the ACP, the way to do this is to use https://stdrs.dev/nightly/x86_64-unknown-linux-gnu/std/iter/fn.repeat_n.html: from_trusted_iterator(iter::repeat_n(x, N)) No need to |
I fear that would lead to suboptimal codegen, since the optimizer has to figure out that counting backwards results in the same amount of iterations as iterating forwards, which in my experience it is not really able to do well. |
You should use the direct implementation unless you have a codegen test demonstrating that the custom implementation is actually better. Counting down can actually be better than counting up, in assembly (example). Regardless of the implementation, it might be good to have some simple tests like checking that |
This comment has been minimized.
This comment has been minimized.
Finally approved in rust-lang/libs-team#310 (comment) ! I'm going to re-run CI as a double-check, since it's been quite a while. |
This comment has been minimized.
This comment has been minimized.
Rebased, updated and tracking issue added. |
Thanks! Excited to finally get this 🙂 @bors r+ rollup=iffy (new codegen test, which isn't tested in CI) |
☀️ Test successful - checks-actions |
Finished benchmarking commit (d8a38b0): comparison URL. Overall result: ❌ regressions - no action needed@rustbot label: -perf-regression Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)Results (primary 3.1%, secondary -3.3%)This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesThis benchmark run did not return any relevant results for this metric. Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 691.194s -> 692.485s (0.19%) |
See rust-lang/libs-team#310.
I've decided to make the function use the input value as last element instead of cloning it to every position and dropping it, and to make this part of the API so that callers are not surprised by this behaviour.
TODO: open a tracking issue. I'll wait for the ACP to be accepted, first.
@rustbot label +T-libs-api +T-libs
r? libs