You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In this function,
func hi() string {
b := make([]byte, 0, 100) // 1st alloc
b = append(b, "Hello, "...)
b = append(b, "world.\n"...)
return string(b) // 2nd alloc, but could be removed.
}
The final line currently generates a call to runtime.slicebytetostring, causing a copy
of b to be allocated.
But the compiler already knows that b doesn't escape. It could instead return a string
header re-using the []byte memory.
sprt, DeedleFake, navytux, tmthrgd, hurkgu and 11 more