From: Jes Cok Date: Thu, 28 Mar 2024 04:50:04 +0000 (+0800) Subject: runtime: make use of builtin clear in tests X-Git-Tag: go1.23rc1~739 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=2830d5457e4120ab9ee475b81205c9f84eed82f8;p=gostls13.git runtime: make use of builtin clear in tests This is a follow-up to CL 574675. Change-Id: I98c3ea968e9c7dc61472849c385a1e697568aa30 Reviewed-on: https://go-review.googlesource.com/c/go/+/574975 Reviewed-by: Ian Lance Taylor Run-TryBot: Jes Cok LUCI-TryBot-Result: Go LUCI TryBot-Result: Gopher Robot Reviewed-by: Than McIntosh Auto-Submit: Ian Lance Taylor --- diff --git a/src/runtime/hash_test.go b/src/runtime/hash_test.go index 08672dbe8a..77f916797f 100644 --- a/src/runtime/hash_test.go +++ b/src/runtime/hash_test.go @@ -339,9 +339,7 @@ type BytesKey struct { } func (k *BytesKey) clear() { - for i := range k.b { - k.b[i] = 0 - } + clear(k.b) } func (k *BytesKey) random(r *rand.Rand) { randBytes(r, k.b) diff --git a/src/runtime/memmove_test.go b/src/runtime/memmove_test.go index 0a97e39d3e..6550c759d6 100644 --- a/src/runtime/memmove_test.go +++ b/src/runtime/memmove_test.go @@ -451,9 +451,7 @@ func BenchmarkGoMemclr(b *testing.B) { benchmarkSizes(b, []int{5, 16, 64, 256}, func(b *testing.B, n int) { x := make([]byte, n) for i := 0; i < b.N; i++ { - for j := range x { - x[j] = 0 - } + clear(x) } }) }