Support shrink to empty#6817
Conversation
0ee84f4 to
5d1abfe
Compare
|
FYI @emilk |
| fn dangling_ptr() -> NonNull<u8> { | ||
| pub(crate) fn dangling_ptr() -> NonNull<u8> { | ||
| // SAFETY: ALIGNMENT is a non-zero usize which is then casted | ||
| // to a *mut T. Therefore, `ptr` is not null and the conditions for |
There was a problem hiding this comment.
Not introduced in this PR, but this function isn't generic, so I am not sure what *mut T is talking about
There was a problem hiding this comment.
I think this is a copy-pasta from NonNull::dangling
|
|
||
| #[inline] | ||
| fn dangling_ptr() -> NonNull<u8> { | ||
| pub(crate) fn dangling_ptr() -> NonNull<u8> { |
There was a problem hiding this comment.
I suggest adding some some comments about this function given its name.
Specifically, that it returns a valid, u8 pointer that is valid for the entire life of the process. Suitable for allocations of 0 length.
I realize it wasn't introduced in this PR, but the name is confusing to me -- Maybe calling it arbtrary_ptr() or something would be less confusing 🤔
There was a problem hiding this comment.
Yeah dangling is an odd name, but is based on what the standard library calls it. I have added some docs to this effect
* Support shrink to empty * Docs * Format
* Add `Array::shrink_to_fit(&mut self)` (#6790) * Add `Array::shrink_to_fit` * Test that shrink_to_fit actually frees memory * Make sure the buffer isn't shared in the test of shrink_to_fit * Remove `#[inline]` * Use `realloc` to reallocate the bytes * Clean up test * Improve docstring for `Array::shrink_to_fit` Co-authored-by: Raphael Taylor-Davies <1781103+tustvold@users.noreply.github.com> * `Buffer::shrink_to_fit`: ignore shared buffers * Improve comment in `ArrayRef::shrink_to_fit` * Document why `try_realloc` is safe, and actually make it safe :) * Improve testing of shrink_to_fit * Fix a few corner cases, and improve test * Add license header to new test file --------- Co-authored-by: Raphael Taylor-Davies <1781103+tustvold@users.noreply.github.com> * Support shrink to empty (#6817) * Support shrink to empty * Docs * Format --------- Co-authored-by: Raphael Taylor-Davies <1781103+tustvold@users.noreply.github.com>
Which issue does this PR close?
Closes #.
Rationale for this change
Follow up to #6790
What changes are included in this PR?
Are there any user-facing changes?