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)
}
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)
}
}
}
+func BenchmarkEfaceCmpDiffIndirect(b *testing.B) {
+ efaceCmp1 = [2]int{1, 2}
+ efaceCmp2 = [2]int{1, 2}
+ for i := 0; i < b.N; i++ {
+ for j := 0; j < 100; j++ {
+ if efaceCmp1 != efaceCmp2 {
+ b.Fatal("bad comparison")
+ }
+ }
+ }
+}
+
func BenchmarkDefer(b *testing.B) {
for i := 0; i < b.N; i++ {
defer1()