mirror of
https://github.com/burrowers/garble.git
synced 2025-10-05 15:56:55 +08:00
slightly improve code thanks to Go 1.18 APIs
strings.Cut makes some string handling code more intuitive. Note that we can't use it everywhere, as some places need LastIndexByte. Start using x/exp/slices, too, which is our first use of generics. Note that its API is experimental and may still change, but since we are not a library, we can control its version updates. I also noticed that we were using TrimSpace for importcfg files. It's actually unnecessary if we swap strings.SplitAfter for Split, as the only whitespace present was the trailing newline. While here, I noticed an unused copy of printfWithoutPackage.
This commit is contained in:
@@ -10,8 +10,9 @@ import (
|
||||
"go/parser"
|
||||
"go/printer"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"golang.org/x/exp/slices"
|
||||
)
|
||||
|
||||
func isDirective(text string) bool {
|
||||
@@ -120,8 +121,8 @@ func printFile(file1 *ast.File) ([]byte, error) {
|
||||
})
|
||||
|
||||
// We add comments in order.
|
||||
sort.Slice(toAdd, func(i, j int) bool {
|
||||
return toAdd[i].offset < toAdd[j].offset
|
||||
slices.SortFunc(toAdd, func(a, b commentToAdd) bool {
|
||||
return a.offset < b.offset
|
||||
})
|
||||
|
||||
copied := 0
|
||||
|
Reference in New Issue
Block a user