cmd/link: make listsort less generic

It's always called with the same arguments now.

Maybe the real fix is to make Symbol.Sub a slice but that requires a bit more
brain.

Change-Id: I1326d34a0a327554be6d54f9bd402ea328224766
Reviewed-on: https://go-review.googlesource.com/27416
Run-TryBot: Michael Hudson-Doyle <michael.hudson@canonical.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
This commit is contained in:
Michael Hudson-Doyle 2016-08-22 10:53:05 +12:00
parent ec8d49c139
commit 82c1e22e13
4 changed files with 28 additions and 43 deletions

View file

@ -238,46 +238,41 @@ func addaddrplus4(ctxt *Link, s *Symbol, t *Symbol, add int64) int64 {
}
/*
* divide-and-conquer list-link
* sort of Symbol* structures.
* Used for the data block.
* divide-and-conquer list-link (by Sub) sort of Symbol* by Value.
* Used for sub-symbols when loading host objects (see e.g. ldelf.go).
*/
func listsubp(s *Symbol) **Symbol {
return &s.Sub
}
func listsort(l *Symbol, cmp func(*Symbol, *Symbol) int, nextp func(*Symbol) **Symbol) *Symbol {
if l == nil || *nextp(l) == nil {
func listsort(l *Symbol) *Symbol {
if l == nil || l.Sub == nil {
return l
}
l1 := l
l2 := l
for {
l2 = *nextp(l2)
l2 = l2.Sub
if l2 == nil {
break
}
l2 = *nextp(l2)
l2 = l2.Sub
if l2 == nil {
break
}
l1 = *nextp(l1)
l1 = l1.Sub
}
l2 = *nextp(l1)
*nextp(l1) = nil
l1 = listsort(l, cmp, nextp)
l2 = listsort(l2, cmp, nextp)
l2 = l1.Sub
l1.Sub = nil
l1 = listsort(l)
l2 = listsort(l2)
/* set up lead element */
if cmp(l1, l2) < 0 {
if l1.Value < l2.Value {
l = l1
l1 = *nextp(l1)
l1 = l1.Sub
} else {
l = l2
l2 = *nextp(l2)
l2 = l2.Sub
}
le := l
@ -285,37 +280,37 @@ func listsort(l *Symbol, cmp func(*Symbol, *Symbol) int, nextp func(*Symbol) **S
for {
if l1 == nil {
for l2 != nil {
*nextp(le) = l2
le.Sub = l2
le = l2
l2 = *nextp(l2)
l2 = l2.Sub
}
*nextp(le) = nil
le.Sub = nil
break
}
if l2 == nil {
for l1 != nil {
*nextp(le) = l1
le.Sub = l1
le = l1
l1 = *nextp(l1)
l1 = l1.Sub
}
break
}
if cmp(l1, l2) < 0 {
*nextp(le) = l1
if l1.Value < l2.Value {
le.Sub = l1
le = l1
l1 = *nextp(l1)
l1 = l1.Sub
} else {
*nextp(le) = l2
le.Sub = l2
le = l2
l2 = *nextp(l2)
l2 = l2.Sub
}
}
*nextp(le) = nil
le.Sub = nil
return l
}