String Builder Optimization (ARCH5071)
Ce contenu n’est pas encore disponible dans votre langue.
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.
Incorrect
Section titled “Incorrect”func label(a, b, c, d, e string) string { return a + "-" + b + "-" + c + "-" + d + "-" + e}Correct
Section titled “Correct”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.