tschaub commented on PR #14026:
URL: https://github.com/apache/arrow/pull/14026#issuecomment-1240877765

   Thanks for digging into this, @zeroshade.
   
   I pushed a commit that doesn't make use of `reflect.SliceHeader`, but it 
does require an extra check for zero length slices.  Considering just the 
`bytesToUint64` function, I think the two variants look like this:
   ```go
   func bytesToUint64V1(b []byte) []uint64 {
        if len(b) == 0 {
                return nil
        }
   
        return unsafe.Slice((*uint64)(unsafe.Pointer(&b[0])), 
cap(b)/uint64SizeBytes)[:len(b)/uint64SizeBytes]
   }
   
   func bytesToUint64V2(b []byte) []uint64 {
        h := (*reflect.SliceHeader)(unsafe.Pointer(&b))
   
        return unsafe.Slice((*uint64)(unsafe.Pointer(h.Data)), 
cap(b)/uint64SizeBytes)[:len(b)/uint64SizeBytes]
   }
   ```
   
   Maybe you'd only notice the difference if you were passing zero length 
slices with non-zero capacity.  Let me know if you think V2 above would be 
preferable.
   


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