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-go.git
The following commit(s) were added to refs/heads/main by this push:
new 9a643a2c optimization: schema: use slices.Sort instead of sort.Slice
(#564)
9a643a2c is described below
commit 9a643a2cc5de1f32fa8408b65addc86e1af55579
Author: pixelherodev <[email protected]>
AuthorDate: Sat Nov 8 13:42:54 2025 -0600
optimization: schema: use slices.Sort instead of sort.Slice (#564)
Shaves off nearly half of the time of Metadata.Equal for me; sort.Slice
takes in `any` as the type of the slice, which requires converting the
slice to an interface - which itself requires allocating and converting
the pointer to the slice header to use as the interface value.
### Rationale for this change
### What changes are included in this PR?
### Are these changes tested?
### Are there any user-facing changes?
---------
Co-authored-by: Noam Preil <[email protected]>
---
arrow/schema.go | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/arrow/schema.go b/arrow/schema.go
index 65702e7b..a9802165 100644
--- a/arrow/schema.go
+++ b/arrow/schema.go
@@ -18,7 +18,7 @@ package arrow
import (
"fmt"
- "sort"
+ "slices"
"strings"
"github.com/apache/arrow-go/v18/arrow/endian"
@@ -56,7 +56,7 @@ func MetadataFrom(kv map[string]string) Metadata {
for k := range kv {
md.keys = append(md.keys, k)
}
- sort.Strings(md.keys)
+ slices.Sort(md.keys)
for _, k := range md.keys {
md.values = append(md.values, kv[k])
}
@@ -129,8 +129,8 @@ func (md Metadata) sortedIndices() []int {
idxes[i] = i
}
- sort.Slice(idxes, func(i, j int) bool {
- return md.keys[idxes[i]] < md.keys[idxes[j]]
+ slices.SortFunc(idxes, func(i, j int) int {
+ return strings.Compare(md.keys[idxes[i]], md.keys[idxes[j]])
})
return idxes
}