Skip to content

std: implement clear via truncate#154095

Open
joboet wants to merge 1 commit intorust-lang:mainfrom
joboet:vec_clear_truncate
Open

std: implement clear via truncate#154095
joboet wants to merge 1 commit intorust-lang:mainfrom
joboet:vec_clear_truncate

Conversation

@joboet
Copy link
Copy Markdown
Member

@joboet joboet commented Mar 19, 2026

This gets rid of some unsafe. truncate(0) is even documented to be equivalent to clear, this makes that equivalence even more obvious.

This gets rid of some `unsafe`. `truncate(0)` is even documented to be
equivalent to `clear`, this makes that equivalence even more obvious.
@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 Mar 19, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Mar 19, 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

@xtqqczze
Copy link
Copy Markdown
Contributor

xtqqczze commented Mar 19, 2026

clear was intentionally implemented this way (rather than using truncate(0)) for performance reasons, as introduced in 9c59d04.

cc: @nnethercote

@Mark-Simulacrum
Copy link
Copy Markdown
Member

r? @nnethercote

@nnethercote
Copy link
Copy Markdown
Contributor

I just wrote a microbenchmark and the difference between the two is still measurable. So I'd prefer to keep the code as is. It would be useful to add a comment explaining why truncate(0) is not used, if you are happy to do that? (I should have done that in #96002.)

@nnethercote nnethercote added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. 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.

5 participants