tustvold commented on code in PR #6790:
URL: https://github.com/apache/arrow-rs/pull/6790#discussion_r1857255351


##########
arrow-buffer/src/buffer/immutable.rs:
##########
@@ -167,6 +167,17 @@ impl Buffer {
         self.data.capacity()
     }
 
+    /// Shrinks the capacity of the buffer as much as possible, freeing unused 
memory.
+    ///
+    /// The capacity of the returned buffer will be the same as [`Self::len`].
+    ///
+    /// If the capacity is already less than or equal to the desired capacity, 
this is a no-op.
+    pub fn shrink_to_fit(&mut self) {
+        if self.len() < self.capacity() {
+            *self = Self::from_vec(self.as_slice().to_vec())
+        }

Review Comment:
   This will always create a fresh allocation and copy across.
   
   I think this should be a no-op if the buffer is shared or externally 
allocated, and otherwise call through to `realloc`. In most cases this will 
avoid any data copying at all, as it will just be adjusting the allocator's 
metadata.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to