oxc icon indicating copy to clipboard operation
oxc copied to clipboard

feat(allocator): add `Vec::into_boxed_slice`

Open DonIsaac opened this issue 1 year ago • 5 comments

Note that this PR does not implement the inverse operation (Box::to_vec for [T]).

DonIsaac avatar Sep 30 '24 22:09 DonIsaac

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.

graphite-app[bot] avatar Sep 30 '24 22:09 graphite-app[bot]

  • #6195 Graphite 👈
  • #6194 Graphite
  • main

This stack of pull requests is managed by Graphite. Learn more about stacking.

Join @DonIsaac and the rest of your teammates on Graphite Graphite

DonIsaac avatar Sep 30 '24 22:09 DonIsaac

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

codspeed-hq[bot] avatar Sep 30 '24 22:09 codspeed-hq[bot]

@overlookmotel does it make sense to just abandon this PR?

DonIsaac avatar Oct 01 '24 19:10 DonIsaac

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.

overlookmotel avatar Oct 01 '24 21:10 overlookmotel

@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.

overlookmotel avatar Oct 11 '24 21:10 overlookmotel

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.

Boshen avatar Oct 12 '24 04:10 Boshen