mirror of
https://github.com/golang/go
synced 2024-11-19 14:24:47 -07:00
500d79c410
Rename memclrrange to signify that it does not handle all types of range clears. Simplify checks to detect the range clear idiom for arrays and slices. Add tests to verify the optimization for the slice range clear idiom is being applied by the compiler. Change-Id: I5c3b7c9a479699ebdb4c407fde692f30f377860c Reviewed-on: https://go-review.googlesource.com/110477 Run-TryBot: Martin Möhrmann <moehrmann@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
33 lines
630 B
Go
33 lines
630 B
Go
// asmcheck
|
|
|
|
// Copyright 2018 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package codegen
|
|
|
|
// This file contains code generation tests related to the handling of
|
|
// slice types.
|
|
|
|
// ------------------ //
|
|
// Clear //
|
|
// ------------------ //
|
|
|
|
// Issue #5373 optimize memset idiom
|
|
|
|
func SliceClear(s []int) []int {
|
|
// amd64:`.*memclrNoHeapPointers`
|
|
for i := range s {
|
|
s[i] = 0
|
|
}
|
|
return s
|
|
}
|
|
|
|
func SliceClearPointers(s []*int) []*int {
|
|
// amd64:`.*memclrHasPointers`
|
|
for i := range s {
|
|
s[i] = nil
|
|
}
|
|
return s
|
|
}
|