Skip to content

Commit

Permalink
apacheGH-37687: [Go] Don't copy in realloc when capacity is sufficien…
Browse files Browse the repository at this point in the history
…t. (apache#37688)

This removes excessive copies observed in some benchmarks.

* Closes: apache#37687

Authored-by: Andrew Chambers <ac@acha.ninja>
Signed-off-by: Matt Topol <zotthewizard@gmail.com>
  • Loading branch information
andrewchambers authored Sep 13, 2023
1 parent 4fac528 commit 15a8ac3
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions go/arrow/memory/go_allocator.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,9 @@ func (a *GoAllocator) Allocate(size int) []byte {
}

func (a *GoAllocator) Reallocate(size int, b []byte) []byte {
if size == len(b) {
return b
if cap(b) >= size {
return b[:size]
}

newBuf := a.Allocate(size)
copy(newBuf, b)
return newBuf
Expand Down

0 comments on commit 15a8ac3

Please sign in to comment.