Skip to content

Commit

Permalink
gen-accessors: Update dumping of getters (#3437)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandear authored Jan 16, 2025
1 parent 2db75de commit d13c739
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions github/gen-accessors.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"go/token"
"log"
"os"
"sort"
"slices"
"strings"
"text/template"
)
Expand Down Expand Up @@ -182,7 +182,9 @@ func (t *templateData) dump() error {
}

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

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

type byName []*getter

func (b byName) Len() int { return len(b) }
func (b byName) Less(i, j int) bool { return b[i].sortVal < b[j].sortVal }
func (b byName) Swap(i, j int) { b[i], b[j] = b[j], b[i] }

const source = `// Copyright {{.Year}} The go-github AUTHORS. All rights reserved.
//
// Use of this source code is governed by a BSD-style
Expand Down

0 comments on commit d13c739

Please sign in to comment.