This is an automated email from the ASF dual-hosted git repository.
zeroshade pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow.git
The following commit(s) were added to refs/heads/main by this push:
new 15a8ac3ce4 GH-37687: [Go] Don't copy in realloc when capacity is
sufficient. (#37688)
15a8ac3ce4 is described below
commit 15a8ac3ce4e3ac31f9f361770ad4a38c69102aa1
Author: andrewchambers <[email protected]>
AuthorDate: Thu Sep 14 05:03:11 2023 +1200
GH-37687: [Go] Don't copy in realloc when capacity is sufficient. (#37688)
This removes excessive copies observed in some benchmarks.
* Closes: #37687
Authored-by: Andrew Chambers <[email protected]>
Signed-off-by: Matt Topol <[email protected]>
---
go/arrow/memory/go_allocator.go | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/go/arrow/memory/go_allocator.go b/go/arrow/memory/go_allocator.go
index 1dea4a8d23..1017eb688d 100644
--- a/go/arrow/memory/go_allocator.go
+++ b/go/arrow/memory/go_allocator.go
@@ -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