mirror of https://github.com/golang/go.git
cmd/compile: don't generate algs for [0]T and [1]T
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>
This commit is contained in:
parent
9ad41f6243
commit
4cef0e980a
|
|
@ -465,6 +465,15 @@ func algtype1(t *Type, bad **Type) int {
|
|||
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:
|
||||
|
|
|
|||
|
|
@ -3193,6 +3193,21 @@ func walkcompare(np **Node, init **NodeList) {
|
|||
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.
|
||||
|
|
|
|||
Loading…
Reference in New Issue