yordan-pavlov commented on a change in pull request #8630:
URL: https://github.com/apache/arrow/pull/8630#discussion_r526371625



##########
File path: rust/arrow/src/buffer.rs
##########
@@ -888,6 +888,15 @@ impl MutableBuffer {
         }
         self.len += bytes.len();
     }
+
+    /// Extends the buffer by `len` with all bytes equal to `0u8`, 
incrementing its capacity if needed.
+    pub fn extend(&mut self, len: usize) {
+        let remaining_capacity = self.capacity - self.len;
+        if len > remaining_capacity {
+            self.reserve(self.len + len);

Review comment:
       @jorgecarleitao  good spot - what I suggested is more obvious when len > 
remaining_capacity such if `len = 256` in your example, then requested capacity 
would be `54 + (256 - (64 - 54)) = 54 + (256 - 10) = 300`; I think it will 
still work even in your example because the requested of 52 capacity will be 
lower than existing capacity so no allocation will be performed as it is not 
necessary because the requested extension of 8 is smaller than remaining 
capacity of 10.




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

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


Reply via email to