diff options
| author | Josh Bleecher Snyder <josharian@gmail.com> | 2018-12-02 10:15:35 -0800 |
|---|---|---|
| committer | Josh Bleecher Snyder <josharian@gmail.com> | 2019-02-27 18:07:25 +0000 |
| commit | 694cd005c3943027a4533a0a534837108ccd66f6 (patch) | |
| tree | 04de439553a192e17473fdd12d0f0744a3f57d3a /src/runtime/alg.go | |
| parent | c33a9511e7ba79177c256e1ff9d7c952ab80104f (diff) | |
| download | go-694cd005c3943027a4533a0a534837108ccd66f6.tar.xz | |
runtime: speed up ifaceeq for direct ifaces
name old time/op new time/op delta
EfaceCmpDiff-8 421ns ± 3% 299ns ± 3% -28.93% (p=0.000 n=92+94)
EfaceCmpDiffIndirect-8 497ns ± 4% 496ns ± 3% ~ (p=0.840 n=98+92)
Change-Id: Id1a8c779413ba35ab0f58d055870b6a0714b51b7
Reviewed-on: https://go-review.googlesource.com/c/152163
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
Diffstat (limited to 'src/runtime/alg.go')
| -rw-r--r-- | src/runtime/alg.go | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/src/runtime/alg.go b/src/runtime/alg.go index 887dbebdeb..1c6795a1fa 100644 --- a/src/runtime/alg.go +++ b/src/runtime/alg.go @@ -224,7 +224,10 @@ func efaceeq(t *_type, x, y unsafe.Pointer) bool { panic(errorString("comparing uncomparable type " + t.string())) } if isDirectIface(t) { - return eq(noescape(unsafe.Pointer(&x)), noescape(unsafe.Pointer(&y))) + // Direct interface types are ptr, chan, map, func, and single-element structs/arrays thereof. + // Maps and funcs are not comparable, so they can't reach here. + // Ptrs, chans, and single-element items can be compared directly using ==. + return x == y } return eq(x, y) } @@ -238,7 +241,8 @@ func ifaceeq(tab *itab, x, y unsafe.Pointer) bool { panic(errorString("comparing uncomparable type " + t.string())) } if isDirectIface(t) { - return eq(noescape(unsafe.Pointer(&x)), noescape(unsafe.Pointer(&y))) + // See comment in efaceeq. + return x == y } return eq(x, y) } |
