From 8e4399ff77e7967543fb9f383511b3f3f8470cda Mon Sep 17 00:00:00 2001 From: Agniva De Sarker Date: Tue, 23 Jul 2019 23:27:28 +0530 Subject: [PATCH] cmd/compile: refactor zero value size to be a constant MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I31dd4fb55d5974cd45de00148039d04f8a7d5cb3 Reviewed-on: https://go-review.googlesource.com/c/go/+/187257 Run-TryBot: Agniva De Sarker TryBot-Result: Gobot Gobot Reviewed-by: Keith Randall Reviewed-by: Martin Möhrmann --- src/cmd/compile/internal/gc/walk.go | 5 +++-- src/runtime/map.go | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/cmd/compile/internal/gc/walk.go b/src/cmd/compile/internal/gc/walk.go index 397f549ab17..1c445603d9b 100644 --- a/src/cmd/compile/internal/gc/walk.go +++ b/src/cmd/compile/internal/gc/walk.go @@ -15,6 +15,7 @@ import ( // The constant is known to runtime. const tmpstringbufsize = 32 +const zeroValSize = 1024 // must match value of runtime/map.go:maxZero func walk(fn *Node) { Curfn = fn @@ -756,7 +757,7 @@ opswitch: // a = *var a := n.List.First() - if w := t.Elem().Width; w <= 1024 { // 1024 must match runtime/map.go:maxZero + if w := t.Elem().Width; w <= zeroValSize { fn := mapfn(mapaccess2[fast], t) r = mkcall1(fn, fn.Type.Results(), init, typename(t), r.Left, key) } else { @@ -1093,7 +1094,7 @@ opswitch: key = nod(OADDR, key, nil) } - if w := t.Elem().Width; w <= 1024 { // 1024 must match runtime/map.go:maxZero + if w := t.Elem().Width; w <= zeroValSize { n = mkcall1(mapfn(mapaccess1[fast], t), types.NewPtr(t.Elem()), init, typename(t), map_, key) } else { z := zeroaddr(w) diff --git a/src/runtime/map.go b/src/runtime/map.go index 386f9655a49..4861cf08db6 100644 --- a/src/runtime/map.go +++ b/src/runtime/map.go @@ -1386,5 +1386,5 @@ func reflect_ismapkey(t *_type) bool { return ismapkey(t) } -const maxZero = 1024 // must match value in cmd/compile/internal/gc/walk.go +const maxZero = 1024 // must match value in cmd/compile/internal/gc/walk.go:zeroValSize var zeroVal [maxZero]byte