feat(allocator): add `Vec::into_boxed_slice`
Note that this PR does not implement the inverse operation (Box::to_vec for [T]).
Your org has enabled the Graphite merge queue for merging into main
Add the label “0-merge” to the PR and Graphite will automatically add it to the merge queue when it’s ready to merge. Or use the label “hotfix” to add to the merge queue as a hot fix.
You must have a Graphite account and log in to Graphite in order to use the merge queue. Sign up using this link.
This stack of pull requests is managed by Graphite. Learn more about stacking.
Join @DonIsaac and the rest of your teammates on
Graphite
CodSpeed Performance Report
Merging #6195 will not alter performance
Comparing don/09-30-feat_allocator_add_vec_into_boxed_slice_ (5ee1ef3) with main (7240ee2)
Summary
✅ 29 untouched benchmarks
@overlookmotel does it make sense to just abandon this PR?
No, I think we can do it. I just think better to use this version:
pub fn into_boxed_slice(self) -> Box<'alloc, [T]> {
let slice = self.0.leak();
let ptr = NonNull::from(slice);
// SAFETY: `ptr` points to a valid slice `[T]`.
// Lifetime of returned `Box<'alloc, [T]>` is same as lifetime of consumed `Vec<'alloc, T>`,
// so data in the `Box` will be valid for its lifetime.
unsafe { Box::from_non_null(ptr) }
}
It's safe, and won't copy memory.
@DonIsaac Hope you don't mind that I've stepped in to finish this off. Just wanted to close a few open PRs which are close to the finish line. Unless you have any objections, I plan to merge this with the additional commits I've added.
Merge activity
- Oct 12, 12:29 AM EDT: The merge label '0-merge' was detected. This PR will be added to the Graphite merge queue once it meets the requirements.
- Oct 12, 12:29 AM EDT: A user added this pull request to the Graphite merge queue.
- Oct 12, 12:35 AM EDT: A user merged this pull request with the Graphite merge queue.