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


##########
arrow-buffer/src/buffer/immutable.rs:
##########
@@ -576,30 +591,30 @@ mod tests {
 
     #[test]
     fn test_shrink_to_fit() {
-        let original = Buffer::from(&[1, 2, 3, 4, 5, 6, 7]);
-        assert_eq!(original.len(), 7);
+        let original = Buffer::from(&[0, 1, 2, 3, 4, 5, 6, 7]);
+        assert_eq!(original.as_slice(), &[0, 1, 2, 3, 4, 5, 6, 7]);
         assert_eq!(original.capacity(), 64);
 
-        let slice = original.slice(3);
+        let slice = original.slice_with_length(2, 3);
         drop(original); // Make sure the buffer isn't shared (or shrink_to_fit 
won't work)
-        assert_eq!(slice.len(), 4);
+        assert_eq!(slice.as_slice(), &[2, 3, 4]);
         assert_eq!(slice.capacity(), 64);
 
         let mut shrunk = slice;
         shrunk.shrink_to_fit();
-        assert_eq!(shrunk.len(), 4);
-        assert_eq!(shrunk.capacity(), 4);
+        assert_eq!(shrunk.as_slice(), &[2, 3, 4]);
+        assert_eq!(shrunk.capacity(), 5); // shrink_to_fit is allowed to keep 
the elements before the offset
 
         // Test that we can handle empty slices:
-        let empty_slice = shrunk.slice(4);
+        let empty_slice = shrunk.slice_with_length(1, 0);
         drop(shrunk); // Make sure the buffer isn't shared (or shrink_to_fit 
won't work)
-        assert_eq!(empty_slice.len(), 0);
-        assert_eq!(empty_slice.capacity(), 4);
+        assert_eq!(empty_slice.as_slice(), &[]);
+        assert_eq!(empty_slice.capacity(), 5);
 
         let mut shrunk_empty = empty_slice;
         shrunk_empty.shrink_to_fit();
-        assert_eq!(shrunk_empty.len(), 0);
-        assert_eq!(shrunk_empty.capacity(), 1); // `Buffer` and `Bytes` 
doesn't support 0-capacity, so we shrink to 1
+        assert_eq!(shrunk_empty.as_slice(), &[]);
+        assert_eq!(shrunk_empty.capacity(), 1); // NOTE: `Buffer` and `Bytes` 
doesn't support 0-capacity

Review Comment:
   For `MutableBuffer` there is special handling for the size=0 case, with a 
[`dangling_ptr`](https://github.com/rerun-io/arrow-rs/blob/3b7cdebbe306b1e58f9ecfb4ce3b7a1b635a5d07/arrow-buffer/src/buffer/mutable.rs#L471-L472)
 helper. We could copy all that logic to `Bytes`, but I rather not add all that 
complexity in this PR.



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