Skip to content

gen-accessors: update dumping of getters #3437

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 16, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading