Skip to content

Use repeat_n in Vec::extend_with#155928

Open
DaniPopes wants to merge 1 commit intorust-lang:mainfrom
DaniPopes:vec-spec-extend-with
Open

Use repeat_n in Vec::extend_with#155928
DaniPopes wants to merge 1 commit intorust-lang:mainfrom
DaniPopes:vec-spec-extend-with

Conversation

@DaniPopes
Copy link
Copy Markdown
Contributor

Simplify Vec::extend_with to use extend(repeat_n(...)). This delegates to extend_trusted which essentially does the same thing but using a single loop; the "don't clone the last element" logic is handled inside of the repeat_n iterator.

This generates slightly better code by removing the manual store of the last element: https://godbolt.org/z/TG6GPY9Eh

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Apr 28, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 28, 2026

r? @Mark-Simulacrum

rustbot has assigned @Mark-Simulacrum.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: libs
  • libs expanded to 7 candidates
  • Random selection from Mark-Simulacrum, jhpratt, nia-e

@rust-log-analyzer

This comment has been minimized.

@DaniPopes DaniPopes force-pushed the vec-spec-extend-with branch from 4361e93 to 88833cf Compare April 28, 2026 14:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants