Zum Inhalt springen

String Builder Optimization (ARCH5071)

Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.

Key go.performance.string-builder-optimization · Severity info · Category performance

Chaining many + operands in a single expression produces intermediate strings. For multi-part concatenation, strings.Join or fmt.Sprintf is clearer and more efficient.

func label(a, b, c, d, e string) string {
return a + "-" + b + "-" + c + "-" + d + "-" + e
}
func label(a, b, c, d, e string) string {
return strings.Join([]string{a, b, c, d, e}, "-")
}

Replace long + chains with strings.Join or fmt.Sprintf.