All [0]T values are equal.
[1]T values are equal iff their sole components are.
This types show up most frequently as a by-product of variadic
function calls, such as fmt.Printf("abc") or fmt.Printf("%v", x).
Cuts 12k off cmd/go and 22k off golang.org/x/tools/cmd/godoc, approx 0.1% each.
For #6853 and #9930
Change-Id: Ic9b7aeb8cc945804246340f6f5e67bbf6008773e
Reviewed-on: https://go-review.googlesource.com/19766
Reviewed-by: David Crawshaw <crawshaw@golang.org>
Run-TryBot: David Crawshaw <crawshaw@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
return a
}
+ switch t.Bound {
+ case 0:
+ // We checked above that the element type is comparable.
+ return AMEM
+ case 1:
+ // Single-element array is same as its lone element.
+ return a
+ }
+
return -1 // needs special compare
case TSTRUCT:
return
}
+ if t.Etype == TARRAY {
+ // Zero- or single-element array, of any type.
+ switch t.Bound {
+ case 0:
+ finishcompare(np, n, Nodbool(n.Op == OEQ), init)
+ return
+ case 1:
+ l0 := Nod(OINDEX, l, Nodintconst(0))
+ r0 := Nod(OINDEX, r, Nodintconst(0))
+ a := Nod(n.Op, l0, r0)
+ finishcompare(np, n, a, init)
+ return
+ }
+ }
+
if t.Etype == TSTRUCT && countfield(t) <= 4 {
// Struct of four or fewer fields.
// Inline comparisons.