Skip to content

Commit

Permalink
feat: replace sort.Slice by slices.SortFunc to improve sort performance
Browse files Browse the repository at this point in the history
  • Loading branch information
tigerwill90 committed Oct 5, 2024
1 parent ed3a282 commit 966ba92
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions node.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
package fox

import (
"sort"
"cmp"
"slices"
"strconv"
"strings"
"sync/atomic"
Expand Down Expand Up @@ -40,12 +41,8 @@ type node struct {
}

func newNode(key string, route *Route, children []*node, catchAllKey string) *node {
// TODO use this instead of old sort.Slice
/* slices.SortFunc(children, func(a, b *node) int {
slices.SortFunc(children, func(a, b *node) int {
return cmp.Compare(a.key, b.key)
})*/
sort.Slice(children, func(i, j int) bool {
return children[i].key < children[j].key
})
nds := make([]atomic.Pointer[node], len(children))
childKeys := make([]byte, len(children))
Expand Down

0 comments on commit 966ba92

Please sign in to comment.