From ec4431eb71e7413b1f89295a5b656599625af9dc Mon Sep 17 00:00:00 2001 From: Oleksandr Redko Date: Thu, 16 Jan 2025 23:36:53 +0200 Subject: [PATCH] gen-accessors: update dumping of getters --- github/gen-accessors.go | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/github/gen-accessors.go b/github/gen-accessors.go index d5d8e5cebd1..261b945e426 100644 --- a/github/gen-accessors.go +++ b/github/gen-accessors.go @@ -22,7 +22,7 @@ import ( "go/token" "log" "os" - "sort" + "slices" "strings" "text/template" ) @@ -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 @@ -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