@@ -12,6 +12,7 @@ import core.Symbols._
12
12
import core .Flags ._
13
13
import ast .Trees ._
14
14
import scala .collection .mutable
15
+ import scala .collection .mutable .LinkedHashMap
15
16
import transform .SymUtils ._
16
17
import config .Printers .simplify
17
18
import Simplify ._
@@ -33,11 +34,11 @@ class InlineLocalObjects(val simplifyPhase: Simplify) extends Optimisation {
33
34
// ValDefs whose lhs is used with `._1` (or any getter call).
34
35
val gettersCalled = mutable.HashSet [Symbol ]()
35
36
36
- // Map from class to new fields, initialised between visitor and transformer.
37
- var newFieldsMapping : Map [Symbol , List [( Symbol , Symbol ) ]] = null
38
- // | | |
39
- // | | New fields, replacements these getters
40
- // | Usages of getters of these classes
37
+ // Immutable sorted map from class to new fields, initialized between visitor and transformer.
38
+ var newFieldsMapping : Map [Symbol , LinkedHashMap [ Symbol , Symbol ]] = null
39
+ // | | |
40
+ // | | New fields, replacements these getters
41
+ // | Usages of getters of these classes
41
42
// ValDefs of the classes that are being torn apart; = candidates.intersect(gettersCalled)
42
43
43
44
def clear (): Unit = {
@@ -57,7 +58,7 @@ class InlineLocalObjects(val simplifyPhase: Simplify) extends Optimisation {
57
58
val info : Type = x.asSeenFrom(refVal.info).info.finalResultType.widenDealias
58
59
ctx.newSymbol(owner, name, flags, info)
59
60
}
60
- (refVal, accessors.zip(newLocals))
61
+ (refVal, LinkedHashMap [ Symbol , Symbol ]( accessors.zip(newLocals) : _* ))
61
62
}.toMap
62
63
}
63
64
@@ -89,7 +90,7 @@ class InlineLocalObjects(val simplifyPhase: Simplify) extends Optimisation {
89
90
initNewFieldsMapping();
90
91
{
91
92
case t @ NewCaseClassValDef (fun, args) if newFieldsMapping.contains(t.symbol) =>
92
- val newFields = newFieldsMapping(t.symbol).map(_._2)
93
+ val newFields = newFieldsMapping(t.symbol).values.toList
93
94
val newFieldsDefs = newFields.zip(args).map { case (nf, arg) =>
94
95
val rhs = arg.changeOwnerAfter(t.symbol, nf.symbol, simplifyPhase)
95
96
ValDef (nf.asTerm, rhs)
@@ -99,11 +100,13 @@ class InlineLocalObjects(val simplifyPhase: Simplify) extends Optimisation {
99
100
Thicket (newFieldsDefs :+ recreate)
100
101
101
102
case t @ Select (rec, _) if isImmutableAccessor(t) =>
102
- newFieldsMapping.getOrElse(rec.symbol, Nil ).collect {
103
- case ((oldSym, newSym)) if oldSym == t.symbol => ref(newSym)
104
- }.headOption.getOrElse(t)
103
+ newFieldsMapping.getOrElse(rec.symbol, Map .empty[Symbol , Symbol ]).get(t.symbol) match {
104
+ case None => t
105
+ case Some (newSym) => ref(newSym)
106
+ }
105
107
106
108
case t => t
107
109
}
108
110
}
109
111
}
112
+
0 commit comments