cmd/compile/internal/gc: eliminate stringsCompare for stackvar sorting

Passes go build -a -toolexec 'toolstash -cmp' std cmd.

Change-Id: I2a87d31da74affdf3d0f358d0efdb3f1c646d917
Reviewed-on: https://go-review.googlesource.com/14759
Reviewed-by: Dave Cheney <dave@cheney.net>
This commit is contained in:
Håvard Haugen 2015-09-19 23:55:27 +02:00 committed by Dave Cheney
parent 7b5af511a5
commit 6d0178359f
3 changed files with 100 additions and 28 deletions

View file

@ -409,9 +409,10 @@ func list(l *NodeList, n *Node) *NodeList {
return concat(l, list1(n))
}
// listsort sorts *l in place according to the 3-way comparison function f.
// listsort sorts *l in place according to the comparison function lt.
// The algorithm expects lt(a, b) to be equivalent to a < b.
// The algorithm is mergesort, so it is guaranteed to be O(n log n).
func listsort(l **NodeList, f func(*Node, *Node) int) {
func listsort(l **NodeList, lt func(*Node, *Node) bool) {
if *l == nil || (*l).Next == nil {
return
}
@ -436,10 +437,10 @@ func listsort(l **NodeList, f func(*Node, *Node) int) {
(*l).End = l1
l1 = *l
listsort(&l1, f)
listsort(&l2, f)
listsort(&l1, lt)
listsort(&l2, lt)
if f(l1.N, l2.N) < 0 {
if lt(l1.N, l2.N) {
*l = l1
} else {
*l = l2
@ -451,7 +452,7 @@ func listsort(l **NodeList, f func(*Node, *Node) int) {
var le *NodeList
for (l1 != nil) && (l2 != nil) {
for (l1.Next != nil) && f(l1.Next.N, l2.N) < 0 {
for (l1.Next != nil) && lt(l1.Next.N, l2.N) {
l1 = l1.Next
}