[dev.fuzz] internal/fuzz: reduce allocation in the mutator
When mutating a byte slice, mutate in place, and only allocate once if
the slice's capacity is less than the maximum size.
mutateBytes already should not allocate; we check a post-condition
that the slice's data pointer does not change.
This speeds up the mutator from 4 ms per value to 200-600 ns. For
example:
goos: darwin
goarch: amd64
pkg: internal/fuzz
cpu: Intel(R) Core(TM) i7-8559U CPU @ 2.70GHz
BenchmarkMutatorBytes/1-8
5908735 275.3 ns/op
BenchmarkMutatorBytes/10-8
5198473 282.0 ns/op
BenchmarkMutatorBytes/100-8
4304750 233.9 ns/op
BenchmarkMutatorBytes/1000-8
4623988 295.2 ns/op
BenchmarkMutatorBytes/10000-8
4252104 458.5 ns/op
BenchmarkMutatorBytes/100000-8
1236751 950.8 ns/op
PASS
ok internal/fuzz 12.993s
Change-Id: I4bf2a04be6c648ef440af2c62bf0ffa3d310172c
Reviewed-on: https://go-review.googlesource.com/c/go/+/306675
Trust: Jay Conrod <jayconrod@google.com>
Trust: Katie Hockman <katie@golang.org>
Run-TryBot: Jay Conrod <jayconrod@google.com>
Reviewed-by: Katie Hockman <katie@golang.org>