Skip to content

Commit c3dcfaf

Browse files
authored
Merge pull request gopherjs#1205 from gopherjs/escapeorder
Improve ordering of EscapingObjects
2 parents 997bc99 + fef762d commit c3dcfaf

File tree

2 files changed

+6
-12
lines changed

2 files changed

+6
-12
lines changed

Diff for: compiler/analysis/escape.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,13 @@ func EscapingObjects(n ast.Node, info *types.Info) []*types.Var {
1414
bottomScopes: make(map[*types.Scope]bool),
1515
}
1616
ast.Walk(&v, n)
17-
var list []*types.Var
18-
for obj := range v.escaping {
19-
list = append(list, obj)
20-
}
21-
return list
17+
return v.ordered
2218
}
2319

2420
type escapeAnalysis struct {
2521
info *types.Info
2622
escaping map[*types.Var]bool
23+
ordered []*types.Var
2724
topScope *types.Scope
2825
bottomScopes map[*types.Scope]bool
2926
}
@@ -57,7 +54,10 @@ func (v *escapingObjectCollector) Visit(node ast.Node) (w ast.Visitor) {
5754
if obj, ok := v.analysis.info.Uses[id].(*types.Var); ok {
5855
for s := obj.Parent(); s != nil; s = s.Parent() {
5956
if s == v.analysis.topScope {
60-
v.analysis.escaping[obj] = true
57+
if !v.analysis.escaping[obj] {
58+
v.analysis.escaping[obj] = true
59+
v.analysis.ordered = append(v.analysis.ordered, obj)
60+
}
6161
break
6262
}
6363
if v.analysis.bottomScopes[s] {

Diff for: compiler/utils.go

-6
Original file line numberDiff line numberDiff line change
@@ -397,12 +397,6 @@ func (fc *funcContext) handleEscapingVars(n ast.Node) {
397397

398398
var names []string
399399
objs := analysis.EscapingObjects(n, fc.pkgCtx.Info.Info)
400-
sort.Slice(objs, func(i, j int) bool {
401-
if objs[i].Name() == objs[j].Name() {
402-
return objs[i].Pos() < objs[j].Pos()
403-
}
404-
return objs[i].Name() < objs[j].Name()
405-
})
406400
for _, obj := range objs {
407401
names = append(names, fc.objectName(obj))
408402
fc.pkgCtx.escapingVars[obj] = true

0 commit comments

Comments
 (0)