Skip to content

Commit

Permalink
Use slices.SortFunc
Browse files Browse the repository at this point in the history
  • Loading branch information
pelletier committed Dec 15, 2023
1 parent f9a1c7a commit cc9c20b
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions compiler/compile.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package compiler

import (
"cmp"
"fmt"
"go/ast"
"go/build/constraint"
Expand All @@ -12,7 +13,6 @@ import (
"path/filepath"
"runtime"
"slices"
"sort"
"strconv"
"strings"

Expand Down Expand Up @@ -405,8 +405,8 @@ func addImports(p *packages.Package, gen *ast.File) *ast.File {

// Imports don't require to be sorted but it helps with output
// stability. The format pass does not take care of this.
sort.Slice(importspecs, func(i, j int) bool {
return importspecs[i].(*ast.ImportSpec).Name.Name < importspecs[j].(*ast.ImportSpec).Name.Name
slices.SortFunc(importspecs, func(a, b ast.Spec) int {
return cmp.Compare(a.(*ast.ImportSpec).Name.Name, b.(*ast.ImportSpec).Name.Name)
})

gen.Decls = append([]ast.Decl{&ast.GenDecl{
Expand Down

0 comments on commit cc9c20b

Please sign in to comment.