summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Zaugg <jzaugg@gmail.com>2016-02-01 14:09:18 +1000
committerJason Zaugg <jzaugg@gmail.com>2016-02-01 14:09:18 +1000
commit6ecb997fa8eb305bf547ec8a6106ba2fd777a594 (patch)
treeaa4138612cbef475817c8db6323b4756973c762b
parent78f0437ac06e71a94a38721751ef5d36ca62c062 (diff)
parent0588b495373148574ab381b67f957957930584cf (diff)
downloadscala-6ecb997fa8eb305bf547ec8a6106ba2fd777a594.tar.gz
scala-6ecb997fa8eb305bf547ec8a6106ba2fd777a594.tar.bz2
scala-6ecb997fa8eb305bf547ec8a6106ba2fd777a594.zip
Merge pull request #4926 from lrytz/scalaTreeMap
mutable.TreeMap instead of java.util.TreeMap in closure optimizer
-rw-r--r--src/compiler/scala/tools/nsc/backend/jvm/opt/ClosureOptimizer.scala10
1 files changed, 4 insertions, 6 deletions
diff --git a/src/compiler/scala/tools/nsc/backend/jvm/opt/ClosureOptimizer.scala b/src/compiler/scala/tools/nsc/backend/jvm/opt/ClosureOptimizer.scala
index 039e6a6d03..b8547e1dc6 100644
--- a/src/compiler/scala/tools/nsc/backend/jvm/opt/ClosureOptimizer.scala
+++ b/src/compiler/scala/tools/nsc/backend/jvm/opt/ClosureOptimizer.scala
@@ -75,10 +75,10 @@ class ClosureOptimizer[BT <: BTypes](val btypes: BT) {
def rewriteClosureApplyInvocations(): Unit = {
// sort all closure invocations to rewrite to ensure bytecode stability
- val toRewrite = new java.util.TreeMap[ClosureInstantiation, mutable.ArrayBuffer[(MethodInsnNode, Int)]](closureInitOrdering)
+ val toRewrite = mutable.TreeMap.empty[ClosureInstantiation, mutable.ArrayBuffer[(MethodInsnNode, Int)]](closureInitOrdering)
def addRewrite(init: ClosureInstantiation, invocation: MethodInsnNode, stackHeight: Int): Unit = {
- if (!toRewrite.containsKey(init)) toRewrite.put(init, mutable.ArrayBuffer.empty[(MethodInsnNode, Int)])
- toRewrite.get(init) += ((invocation, stackHeight))
+ val callsites = toRewrite.getOrElseUpdate(init, mutable.ArrayBuffer.empty[(MethodInsnNode, Int)])
+ callsites += ((invocation, stackHeight))
}
// For each closure instantiation find callsites of the closure and add them to the toRewrite
@@ -113,9 +113,7 @@ class ClosureOptimizer[BT <: BTypes](val btypes: BT) {
case _ =>
}
- for (entry <- toRewrite.entrySet.iterator().asScala) {
- val closureInit = entry.getKey
- val invocations = entry.getValue
+ for ((closureInit, invocations) <- toRewrite) {
// Local variables that hold the captured values and the closure invocation arguments.
val (localsForCapturedValues, argumentLocalsList) = localsForClosureRewrite(closureInit)
for ((invocation, stackHeight) <- invocations)