diff options
author | Lukas Rytz <lukas.rytz@gmail.com> | 2014-11-07 09:02:23 +0100 |
---|---|---|
committer | Lukas Rytz <lukas.rytz@gmail.com> | 2014-11-07 09:03:46 +0100 |
commit | 063e7741510bfaf4ccb61f7c0d94cae9353183aa (patch) | |
tree | 0ac2a744cfa5ed15a5b3b72e370d050de4c8099a /src | |
parent | d39525ac06c8d319b43d3388d624fb2c1dcbd601 (diff) | |
download | scala-063e7741510bfaf4ccb61f7c0d94cae9353183aa.tar.gz scala-063e7741510bfaf4ccb61f7c0d94cae9353183aa.tar.bz2 scala-063e7741510bfaf4ccb61f7c0d94cae9353183aa.zip |
Address review comments
Diffstat (limited to 'src')
-rw-r--r-- | src/compiler/scala/tools/nsc/backend/jvm/opt/BytecodeUtils.scala | 8 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/backend/jvm/opt/LocalOpt.scala | 15 |
2 files changed, 14 insertions, 9 deletions
diff --git a/src/compiler/scala/tools/nsc/backend/jvm/opt/BytecodeUtils.scala b/src/compiler/scala/tools/nsc/backend/jvm/opt/BytecodeUtils.scala index fd14083cf7..6b4047c0a7 100644 --- a/src/compiler/scala/tools/nsc/backend/jvm/opt/BytecodeUtils.scala +++ b/src/compiler/scala/tools/nsc/backend/jvm/opt/BytecodeUtils.scala @@ -9,6 +9,7 @@ package opt import scala.annotation.{tailrec, switch} import scala.collection.mutable +import scala.reflect.internal.util.Collections._ import scala.tools.asm.Opcodes import scala.tools.asm.tree._ import scala.collection.convert.decorateAsScala._ @@ -55,6 +56,11 @@ object BytecodeUtils { (op >= Opcodes.IFEQ && op <= Opcodes.IF_ACMPNE) || op == Opcodes.IFNULL || op == Opcodes.IFNONNULL } + def isReturn(instruction: AbstractInsnNode): Boolean = { + val op = instruction.getOpcode + op >= Opcodes.IRETURN && op <= Opcodes.RETURN + } + def isVarInstruction(instruction: AbstractInsnNode): Boolean = { val op = instruction.getOpcode (op >= Opcodes.ILOAD && op <= Opcodes.ALOAD) || (op >= Opcodes.ISTORE && op <= Opcodes.ASTORE) @@ -157,7 +163,7 @@ object BytecodeUtils { def substituteLabel(reference: AnyRef, from: LabelNode, to: LabelNode): Unit = { def substList(list: java.util.List[LabelNode]) = { - list.asScala.zipWithIndex.foreach { case (l, i) => + foreachWithIndex(list.asScala.toList) { case (l, i) => if (l == from) list.set(i, to) } } diff --git a/src/compiler/scala/tools/nsc/backend/jvm/opt/LocalOpt.scala b/src/compiler/scala/tools/nsc/backend/jvm/opt/LocalOpt.scala index 8fff478326..273112b93c 100644 --- a/src/compiler/scala/tools/nsc/backend/jvm/opt/LocalOpt.scala +++ b/src/compiler/scala/tools/nsc/backend/jvm/opt/LocalOpt.scala @@ -245,7 +245,7 @@ class LocalOpt(settings: ScalaSettings) { private def parametersSize(method: MethodNode): Int = { // Double / long fields occupy two slots, so we sum up the sizes. Since getSize returns 0 for // void, we have to add `max 1`. - val paramsSize = scala.tools.asm.Type.getArgumentTypes(method.desc).map(_.getSize max 1).sum + val paramsSize = scala.tools.asm.Type.getArgumentTypes(method.desc).iterator.map(_.getSize max 1).sum val thisSize = if ((method.access & Opcodes.ACC_STATIC) == 0) 1 else 0 paramsSize + thisSize } @@ -273,15 +273,15 @@ class LocalOpt(settings: ScalaSettings) { } // Ensure the length of `renumber`. Unused variable indices are mapped to -1. - val minLenght = if (isWide) index + 2 else index + 1 - for (i <- renumber.length until minLenght) renumber += -1 + val minLength = if (isWide) index + 2 else index + 1 + for (i <- renumber.length until minLength) renumber += -1 renumber(index) = index if (isWide) renumber(index + 1) = index } // first phase: collect all used local variables. if the variable at index x is used, set - // renumber(x) = x, otherwsie renumber(x) = -1. if the variable is wide (long or doulbe), set + // renumber(x) = x, otherwise renumber(x) = -1. if the variable is wide (long or double), set // renumber(x+1) = x. val firstLocalIndex = parametersSize(method) @@ -404,7 +404,7 @@ class LocalOpt(settings: ScalaSettings) { def simplifyJumps(method: MethodNode): Boolean = { var changed = false - val allHanlders = method.tryCatchBlocks.asScala.toSet + val allHandlers = method.tryCatchBlocks.asScala.toSet // A set of all exception handlers that guard the current instruction, required for simplifyGotoReturn var activeHandlers = Set.empty[TryCatchBlockNode] @@ -420,7 +420,7 @@ class LocalOpt(settings: ScalaSettings) { instruction match { case l: LabelNode => - activeHandlers ++= allHanlders.filter(_.start == l) + activeHandlers ++= allHandlers.filter(_.start == l) activeHandlers = activeHandlers.filter(_.end != l) case _ => } @@ -550,8 +550,7 @@ class LocalOpt(settings: ScalaSettings) { case Goto(jump) => nextExecutableInstruction(jump.label) match { case Some(target) => - val op = target.getOpcode - if ((op >= Opcodes.IRETURN && op <= Opcodes.RETURN) || op == Opcodes.ATHROW) { + if (isReturn(target) || target.getOpcode == Opcodes.ATHROW) { method.instructions.set(jump, target.clone(null)) true } else false |