style: modernize to splitseq, cut, min, maps.copy and range-over-int

This commit is contained in:
2026-08-29 16:04:32 +02:00
parent eacf33d0f7
commit 9beff4ae85
40 changed files with 90 additions and 234 deletions
+11 -23
View File
@@ -359,7 +359,7 @@ unreachable-code, register-clobber and funcdata-pcdata.
return 2
}
disabled := map[string]bool{}
for _, code := range strings.Split(*disable, ",") {
for code := range strings.SplitSeq(*disable, ",") {
if code = strings.TrimSpace(code); code != "" {
disabled[code] = true
}
@@ -460,10 +460,7 @@ requires -p, the package path, and the installed Go toolchain).
code := img.Code[fn.Offset : fn.Offset+fn.Size]
fmt.Printf("%s: %d bytes\n", fn.Name, fn.Size)
for i := 0; i < len(code); i += 16 {
end := i + 16
if end > len(code) {
end = len(code)
}
end := min(i+16, len(code))
fmt.Printf(" %04x:", i)
for _, b := range code[i:end] {
fmt.Printf(" %02x", b)
@@ -485,10 +482,7 @@ requires -p, the package path, and the installed Go toolchain).
fmt.Printf(" %s: %d bytes at 0x%x\n", g.Name.Name, size, img.Symbols[g.Name.Name])
}
for i := 0; i < len(img.Data); i += 16 {
end := i + 16
if end > len(img.Data) {
end = len(img.Data)
}
end := min(i+16, len(img.Data))
fmt.Printf(" %04x:", len(img.Code)+i)
for _, b := range img.Data[i:end] {
fmt.Printf(" %02x", b)
@@ -570,7 +564,7 @@ e.g. --map wideCopyAVX2=wideCopyAVX512 pairs the two regardless of suffix.
// Parse the name mapping (file1 name → file2 name).
nameMap := make(map[string]string)
if *mapSpec != "" {
for _, pair := range strings.Split(*mapSpec, ",") {
for pair := range strings.SplitSeq(*mapSpec, ",") {
old, new, ok := strings.Cut(pair, "=")
if !ok || old == "" || new == "" {
fmt.Fprintf(os.Stderr, "gasm diff: invalid --map pair %q (expected old=new)\n", pair)
@@ -679,10 +673,7 @@ func assemblePath(path string) (*asm.Image, error) {
// printByteDiff shows the first few byte differences between two code blocks.
func printByteDiff(a, b []byte) {
maxLen := len(a)
if len(b) < maxLen {
maxLen = len(b)
}
maxLen := min(len(b), len(a))
shown := 0
for i := 0; i < maxLen && shown < 8; i++ {
if a[i] != b[i] {
@@ -1344,8 +1335,8 @@ func fuzzInSubprocess(path, funcName string, n int) string {
}
}
// Non-zero exit without a signal: the fuzz reported mismatches.
lines := strings.Split(strings.TrimSpace(string(out)), "\n")
for _, l := range lines {
lines := strings.SplitSeq(strings.TrimSpace(string(out)), "\n")
for l := range lines {
if strings.Contains(l, funcName) {
return strings.TrimSpace(l)
}
@@ -1353,8 +1344,8 @@ func fuzzInSubprocess(path, funcName string, n int) string {
return fmt.Sprintf("%s: FAIL (exit %v)", funcName, err)
}
// Success: extract the result line.
lines := strings.Split(strings.TrimSpace(string(out)), "\n")
for _, l := range lines {
lines := strings.SplitSeq(strings.TrimSpace(string(out)), "\n")
for l := range lines {
if strings.Contains(l, funcName) {
return strings.TrimSpace(l)
}
@@ -1400,7 +1391,7 @@ func sweepInSubprocess(path, funcName string, smoke, abi bool, abiN int) (string
// dropping the child's own file/function banners (the parent prints those).
func sweepCheckLines(out []byte) string {
var lines []string
for _, l := range strings.Split(string(out), "\n") {
for l := range strings.SplitSeq(string(out), "\n") {
t := strings.TrimSpace(l)
if strings.HasPrefix(t, "smoke:") || strings.HasPrefix(t, "abi:") {
lines = append(lines, " "+t)
@@ -1570,10 +1561,7 @@ func formatResults(rs []verify.Param) string {
// hexDump returns a one-line hex dump of buf, truncated to 64 bytes.
func hexDump(buf []byte) string {
const max = 64
n := len(buf)
if n > max {
n = max
}
n := min(len(buf), max)
var sb strings.Builder
for i := range n {
if i > 0 {