Skip to content

Commit 0273ffe

Browse files
author
Noam Preil
committed
optimization: allocator: remove unnecessary branch
In branch 1, shift is defined as next-addr. We then slice buf with shift as the offset, and with size+shift as length and capacity. In branch 2, addr == next, and thus shift == 0. size+shift == size. The slice statements are thus equivalent; there's no reason to be branching here.
1 parent 2d3593f commit 0273ffe

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

arrow/memory/go_allocator.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,8 @@ func (a *GoAllocator) Allocate(size int) []byte {
2424
buf := make([]byte, size+alignment) // padding for 64-byte alignment
2525
addr := int(addressOf(buf))
2626
next := roundUpToMultipleOf64(addr)
27-
if addr != next {
28-
shift := next - addr
29-
return buf[shift : size+shift : size+shift]
30-
}
31-
return buf[:size:size]
27+
shift := next - addr
28+
return buf[shift : size+shift : size+shift]
3229
}
3330

3431
func (a *GoAllocator) Reallocate(size int, b []byte) []byte {

0 commit comments

Comments
 (0)