Skip to content

Commit d13c739

Browse files
authored
gen-accessors: Update dumping of getters (#3437)
1 parent 2db75de commit d13c739

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

github/gen-accessors.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
"go/token"
2323
"log"
2424
"os"
25-
"sort"
25+
"slices"
2626
"strings"
2727
"text/template"
2828
)
@@ -182,7 +182,9 @@ func (t *templateData) dump() error {
182182
}
183183

184184
// Sort getters by ReceiverType.FieldName.
185-
sort.Sort(byName(t.Getters))
185+
slices.SortStableFunc(t.Getters, func(a, b *getter) int {
186+
return strings.Compare(a.sortVal, b.sortVal)
187+
})
186188

187189
processTemplate := func(tmpl *template.Template, filename string) error {
188190
var buf bytes.Buffer
@@ -344,12 +346,6 @@ type getter struct {
344346
ArrayType bool
345347
}
346348

347-
type byName []*getter
348-
349-
func (b byName) Len() int { return len(b) }
350-
func (b byName) Less(i, j int) bool { return b[i].sortVal < b[j].sortVal }
351-
func (b byName) Swap(i, j int) { b[i], b[j] = b[j], b[i] }
352-
353349
const source = `// Copyright {{.Year}} The go-github AUTHORS. All rights reserved.
354350
//
355351
// Use of this source code is governed by a BSD-style

0 commit comments

Comments
 (0)