go/build/constraint: use strings.Builder instead of for { str+=str }

(This works around a bug in the stringsbuilder modernizer.)

For #76476

Change-Id: I1cb8715fd79c0363cb9c159686eaeb3482c93228
Reviewed-on: https://go-review.googlesource.com/c/go/+/724721
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
TryBot-Bypass: Alan Donovan <adonovan@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
This commit is contained in:
Alan Donovan 2025-11-26 17:53:04 -05:00
parent 0f6397384b
commit 0c747b7aa7

View file

@ -515,18 +515,18 @@ func PlusBuildLines(x Expr) ([]string, error) {
// Prepare the +build lines. // Prepare the +build lines.
var lines []string var lines []string
for _, or := range split { for _, or := range split {
line := "// +build" var line strings.Builder
line.WriteString("// +build")
for _, and := range or { for _, and := range or {
clause := "" line.WriteString(" ")
for i, lit := range and { for i, lit := range and {
if i > 0 { if i > 0 {
clause += "," line.WriteString(",")
} }
clause += lit.String() line.WriteString(lit.String())
} }
line += " " + clause
} }
lines = append(lines, line) lines = append(lines, line.String())
} }
return lines, nil return lines, nil