@@ -70,24 +70,24 @@ class ClosureOptimizer[BT <: BTypes](val btypes: BT) {
70
70
}
71
71
}
72
72
73
- // Group the closure instantiations by method allows running the ProdConsAnalyzer only once per method.
74
- // Also sort the instantiations: If there are multiple closure instantiations in a method, closure
75
- // invocations need to be re-written in a consistent order for bytecode stability. The local variable
76
- // slots for storing captured values depends on the order of rewriting.
73
+ // Grouping the closure instantiations by method allows running the ProdConsAnalyzer only once per
74
+ // method. Also sort the instantiations: If there are multiple closure instantiations in a method,
75
+ // closure invocations need to be re-written in a consistent order for bytecode stability. The local
76
+ // variable slots for storing captured values depends on the order of rewriting.
77
77
val closureInstantiationsByMethod : Map [MethodNode , immutable.TreeSet [ClosureInstantiation ]] = {
78
78
closureInstantiations.values.groupBy(_.ownerMethod).mapValues(immutable.TreeSet .empty ++ _)
79
79
}
80
80
81
81
// For each closure instantiation, a list of callsites of the closure that can be re-written
82
82
// If a callsite cannot be rewritten, for example because the lambda body method is not accessible,
83
83
// a warning is returned instead.
84
- val callsitesToRewrite : Map [ ClosureInstantiation , List [Either [RewriteClosureApplyToClosureBodyFailed , (MethodInsnNode , Int )]]] = {
85
- closureInstantiationsByMethod flatMap {
84
+ val callsitesToRewrite : List [( ClosureInstantiation , List [Either [RewriteClosureApplyToClosureBodyFailed , (MethodInsnNode , Int )]]) ] = {
85
+ closureInstantiationsByMethod.iterator. flatMap( {
86
86
case (methodNode, closureInits) =>
87
87
// A lazy val to ensure the analysis only runs if necessary (the value is passed by name to `closureCallsites`)
88
88
lazy val prodCons = new ProdConsAnalyzer (methodNode, closureInits.head.ownerClass.internalName)
89
- closureInits.map(init => (init, closureCallsites(init, prodCons)))
90
- }
89
+ closureInits.iterator. map(init => (init, closureCallsites(init, prodCons)))
90
+ }).toList // mapping to a list (not a map) to keep the sorting of closureInstantiationsByMethod
91
91
}
92
92
93
93
// Rewrite all closure callsites (or issue inliner warnings for those that cannot be rewritten)
0 commit comments