From 0588b495373148574ab381b67f957957930584cf Mon Sep 17 00:00:00 2001 From: Lukas Rytz Date: Thu, 28 Jan 2016 14:21:48 +0100 Subject: mutable.TreeMap instead of java.util.TreeMap in closure optimizer --- .../scala/tools/nsc/backend/jvm/opt/ClosureOptimizer.scala | 10 ++++------ 1 file 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) -- cgit v1.2.3