Skip to content

Commit 879e78a

Browse files
author
Noam Preil
committed
optimization: schema: use slices.Sort instead of sort.Slice
Shaves off ~1/3rd 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.
1 parent f657566 commit 879e78a

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

arrow/schema.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package arrow
1818

1919
import (
2020
"fmt"
21+
"slices"
2122
"sort"
2223
"strings"
2324

@@ -129,8 +130,8 @@ func (md Metadata) sortedIndices() []int {
129130
idxes[i] = i
130131
}
131132

132-
sort.Slice(idxes, func(i, j int) bool {
133-
return md.keys[idxes[i]] < md.keys[idxes[j]]
133+
slices.SortFunc(idxes, func(i, j int) int {
134+
return strings.Compare(md.keys[idxes[i]], md.keys[idxes[j]])
134135
})
135136
return idxes
136137
}

0 commit comments

Comments
 (0)