"cmd/internal/sys"
"cmd/link/internal/loader"
"cmd/link/internal/sym"
+ "container/heap"
"fmt"
"unicode"
)
type workQueue []loader.Sym
-func (q *workQueue) push(i loader.Sym) { *q = append(*q, i) }
-func (q *workQueue) pop() loader.Sym { i := (*q)[len(*q)-1]; *q = (*q)[:len(*q)-1]; return i }
+// Implement container/heap.Interface.
+func (q *workQueue) Len() int { return len(*q) }
+func (q *workQueue) Less(i, j int) bool { return (*q)[i] < (*q)[j] }
+func (q *workQueue) Swap(i, j int) { (*q)[i], (*q)[j] = (*q)[j], (*q)[i] }
+func (q *workQueue) Push(i interface{}) { *q = append(*q, i.(loader.Sym)) }
+func (q *workQueue) Pop() interface{} { i := (*q)[len(*q)-1]; *q = (*q)[:len(*q)-1]; return i }
+
+// Functions for deadcode pass to use.
+// Deadcode pass should call push/pop, not Push/Pop.
+func (q *workQueue) push(i loader.Sym) { heap.Push(q, i) }
+func (q *workQueue) pop() loader.Sym { return heap.Pop(q).(loader.Sym) }
func (q *workQueue) empty() bool { return len(*q) == 0 }
type deadcodePass2 struct {
if d.ctxt.Reachparent != nil {
d.ldr.Reachparent = make([]loader.Sym, d.ldr.NSym())
}
+ heap.Init(&d.wq)
if d.ctxt.BuildMode == BuildModeShared {
// Mark all symbols defined in this library as reachable when