]> Cypherpunks repositories - gostls13.git/commit
cmd/internal/gc: inline x := y.(*T) and x, ok := y.(*T)
authorRuss Cox <rsc@golang.org>
Fri, 20 Mar 2015 04:06:10 +0000 (00:06 -0400)
committerRuss Cox <rsc@golang.org>
Fri, 20 Mar 2015 20:05:37 +0000 (20:05 +0000)
commit4224d81fae7bfce98629894d14f4644018037cfb
treea69bfb0356406df650405a15ceee342f33313549
parentb115c35ee337ac6026539802d2ff085949dd1919
cmd/internal/gc: inline x := y.(*T) and x, ok := y.(*T)

These can be implemented with just a compare and a move instruction.
Do so, avoiding the overhead of a call into the runtime.

These assertions are a significant cost in Go code that uses interface{}
as a safe alternative to C's void* (or unsafe.Pointer), such as the
current version of the Go compiler.

*T here includes pointer to T but also any Go type represented as
a single pointer (chan, func, map). It does not include [1]*T or struct{*int}.
That requires more work in other parts of the compiler; there is a TODO.

Change-Id: I7ff681c20d2c3eb6ad11dd7b3a37b1f3dda23965
Reviewed-on: https://go-review.googlesource.com/7862
Reviewed-by: Rob Pike <r@golang.org>
12 files changed:
src/cmd/internal/gc/builtin.go
src/cmd/internal/gc/builtin/runtime.go
src/cmd/internal/gc/cgen.go
src/cmd/internal/gc/gen.go
src/cmd/internal/gc/go.go
src/cmd/internal/gc/lex.go
src/cmd/internal/gc/order.go
src/cmd/internal/gc/typecheck.go
src/cmd/internal/gc/walk.go
src/runtime/error.go
src/runtime/iface.go
test/interface/assertinline.go [new file with mode: 0644]