diff options
| author | Keith Randall <khr@golang.org> | 2017-03-24 14:03:15 -0700 |
|---|---|---|
| committer | Keith Randall <khr@golang.org> | 2017-03-24 23:03:09 +0000 |
| commit | e67d881bc3708d38fbe485d2264f38a699ce11fd (patch) | |
| tree | c118cc7dfd2796046fd50852bc14856b37f16d65 /src/runtime/alg.go | |
| parent | c026c37f33c6037dcf71e16a1e79f78f3b5165c4 (diff) | |
| download | go-e67d881bc3708d38fbe485d2264f38a699ce11fd.tar.xz | |
cmd/compile: simplify efaceeq and ifaceeq
Clean up code that does interface equality. Avoid doing checks
in efaceeq/ifaceeq that we already did before calling those routines.
No noticeable performance changes for existing benchmarks.
name old time/op new time/op delta
EfaceCmpDiff-8 604ns ± 1% 553ns ± 1% -8.41% (p=0.000 n=9+10)
Fixes #18618
Change-Id: I3bd46db82b96494873045bc3300c56400bc582eb
Reviewed-on: https://go-review.googlesource.com/38606
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: David Chase <drchase@google.com>
Diffstat (limited to 'src/runtime/alg.go')
| -rw-r--r-- | src/runtime/alg.go | 32 |
1 files changed, 14 insertions, 18 deletions
diff --git a/src/runtime/alg.go b/src/runtime/alg.go index 5c378c6a2a..504be61cd0 100644 --- a/src/runtime/alg.go +++ b/src/runtime/alg.go @@ -206,16 +206,16 @@ func strequal(p, q unsafe.Pointer) bool { return *(*string)(p) == *(*string)(q) } func interequal(p, q unsafe.Pointer) bool { - return ifaceeq(*(*iface)(p), *(*iface)(q)) + x := *(*iface)(p) + y := *(*iface)(q) + return x.tab == y.tab && ifaceeq(x.tab, x.data, y.data) } func nilinterequal(p, q unsafe.Pointer) bool { - return efaceeq(*(*eface)(p), *(*eface)(q)) + x := *(*eface)(p) + y := *(*eface)(q) + return x._type == y._type && efaceeq(x._type, x.data, y.data) } -func efaceeq(x, y eface) bool { - t := x._type - if t != y._type { - return false - } +func efaceeq(t *_type, x, y unsafe.Pointer) bool { if t == nil { return true } @@ -224,27 +224,23 @@ func efaceeq(x, y eface) bool { panic(errorString("comparing uncomparable type " + t.string())) } if isDirectIface(t) { - return eq(noescape(unsafe.Pointer(&x.data)), noescape(unsafe.Pointer(&y.data))) + return eq(noescape(unsafe.Pointer(&x)), noescape(unsafe.Pointer(&y))) } - return eq(x.data, y.data) + return eq(x, y) } -func ifaceeq(x, y iface) bool { - xtab := x.tab - if xtab != y.tab { - return false - } - if xtab == nil { +func ifaceeq(tab *itab, x, y unsafe.Pointer) bool { + if tab == nil { return true } - t := xtab._type + t := tab._type eq := t.alg.equal if eq == nil { panic(errorString("comparing uncomparable type " + t.string())) } if isDirectIface(t) { - return eq(noescape(unsafe.Pointer(&x.data)), noescape(unsafe.Pointer(&y.data))) + return eq(noescape(unsafe.Pointer(&x)), noescape(unsafe.Pointer(&y))) } - return eq(x.data, y.data) + return eq(x, y) } // Testing adapters for hash quality tests (see hash_test.go) |
