Open
Description
https://go-review.googlesource.com/#/c/8200/ added a benchmark to the strings package that shows strings.Trim and its variants allocate memory. The allocation is caused by the call to makeCutsetFunc here. Inlining this call removes the allocation and provides a nice performance boost to Trim. You can see the effect on the benchmark using Go Tip (commit 6262192) below:
benchmark old ns/op new ns/op delta
BenchmarkTrim 3204 2323 -27.50%
benchmark old allocs new allocs delta
BenchmarkTrim 11 0 -100.00%
benchmark old bytes new bytes delta
BenchmarkTrim 352 0 -100.00%
makeCutsetFunc is a pretty simple function (all it does is return a closure), and it was pointed out in review that it might be nice to inline functions like it in the compiler rather than changing strings.Trim explicitly.