-
-
Notifications
You must be signed in to change notification settings - Fork 721
feat(data_structures): add Stack::clear
#14028
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
feat(data_structures): add Stack::clear
#14028
Conversation
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
CodSpeed Instrumentation Performance ReportMerging #14028 will not alter performanceComparing Summary
|
c5758c6 to
3c3cdb2
Compare
ed0d229 to
20c266b
Compare
overlookmotel
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self.is_empty() check may not actually be required. When the stack's content type (T) is non-Drop, self.drop_contents() becomes a no-op anyway. So if we could remove self.is_empty() check,this function becomes just a single instruction and no branches, when T is non-Drop.
drop_contents has a safety comment saying "Stack must be allocated", but I'm not sure it's actually required. I think it's fine to call ptr::drop_in_place with an empty slice. But let's leave it as is - maybe there was a reason I added this safety constraint which I don't remember right now.
|
When the stack is not allocated, |
3c3cdb2 to
13de0f7
Compare
20c266b to
909a086
Compare
Yeah, I think that's what I had in mind at the time I wrote the code. But now I think probably it is legal to create a slice starting at a dangling pointer, as long as it's 0 length (dangling pointers are correctly aligned). Anyway, it doesn't really matter much. This PR just made me think about it again. |
Merge activity
|
Added `Stack::clear` for #14029.
13de0f7 to
1521a1f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.
Ah, I see. I think it's legal. I've just found this:
...which is what we're doing here. |
Nice. I hadn't spotted that in docs before. |

Added
Stack::clearfor #14029.