-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Support shrink to empty #6817
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
Support shrink to empty #6817
Conversation
0ee84f4 to
5d1abfe
Compare
|
FYI @emilk |
alamb
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.
Thanks @tustvold -- makes sense to me
arrow-buffer/src/buffer/mutable.rs
Outdated
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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?