Optimize the generic zero value (#27102)

allocate by declare,
this make it possible to allocate the value in stack,
faster and less presure for GC

Signed-off-by: yah01 <yah2er0ne@outlook.com>
pull/27109/head
yah01 2023-09-14 19:05:20 +08:00 committed by GitHub
parent 7bb20fa394
commit 0f2883ef9d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 1 deletions

View File

@ -19,7 +19,8 @@ package generic
import "reflect"
func Zero[T any]() T {
return *new(T)
var zero T
return zero
}
func IsZero[T any](v T) bool {