aboutsummaryrefslogtreecommitdiff
path: root/test/nilcheck.go
diff options
context:
space:
mode:
authorJosh Bleecher Snyder <josharian@gmail.com>2014-12-22 11:33:47 -0800
committerJosh Bleecher Snyder <josharian@gmail.com>2015-01-07 22:36:06 +0000
commit43e6923131c4c83e02f5263a9632d81819f15a62 (patch)
tree0300e13f1f583aaac87fef92c999c9e50d1908f5 /test/nilcheck.go
parent43c87aa481f4e10777b05bf05edd15403853348f (diff)
downloadgo-43e6923131c4c83e02f5263a9632d81819f15a62.tar.gz
go-43e6923131c4c83e02f5263a9632d81819f15a62.zip
cmd/gc: optimize existence-only map lookups
The compiler converts 'val, ok = m[key]' to tmp, ok = <runtime call> val = *tmp For lookups of the form '_, ok = m[key]', the second statement is unnecessary. By not generating it we save a nil check. Change-Id: I21346cc195cb3c62e041af8b18770c0940358695 Reviewed-on: https://go-review.googlesource.com/1975 Reviewed-by: Russ Cox <rsc@golang.org>
Diffstat (limited to 'test/nilcheck.go')
-rw-r--r--test/nilcheck.go5
1 files changed, 5 insertions, 0 deletions
diff --git a/test/nilcheck.go b/test/nilcheck.go
index fe05d05c92..99c3c5fdb6 100644
--- a/test/nilcheck.go
+++ b/test/nilcheck.go
@@ -182,3 +182,8 @@ func f4(x *[10]int) {
_ = &x[9] // ERROR "nil check"
}
+func f5(m map[string]struct{}) bool {
+ // Existence-only map lookups should not generate a nil check
+ _, ok := m[""]
+ return ok
+}