diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2014-10-08 13:09:24 +1000 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2014-10-10 15:23:39 +1000 |
commit | 10b0d216a3e3b011103a7c939fabe441440f9aa1 (patch) | |
tree | 80d2a2cead2942224ee26735746599b6cc48aca5 /src | |
parent | f6d72991bbba9a9610a9873424b3506f2b26be3f (diff) | |
download | scala-10b0d216a3e3b011103a7c939fabe441440f9aa1.tar.gz scala-10b0d216a3e3b011103a7c939fabe441440f9aa1.tar.bz2 scala-10b0d216a3e3b011103a7c939fabe441440f9aa1.zip |
Avoid wasteful array creation in backend
The iteration is only needed to side effect on `instructionList`
and `code.touched`. This commit uses an iterator and `foreach`,
rather than creating throwaway Arrays.
% time (for f in {1..200}; do echo test/files/pos/t8893.scala; done | qscalac -Xresident)
Before: 30s
After : 21s
Diffstat (limited to 'src')
-rw-r--r-- | src/compiler/scala/tools/nsc/backend/icode/BasicBlocks.scala | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/src/compiler/scala/tools/nsc/backend/icode/BasicBlocks.scala b/src/compiler/scala/tools/nsc/backend/icode/BasicBlocks.scala index f9551697d2..ad1975ef23 100644 --- a/src/compiler/scala/tools/nsc/backend/icode/BasicBlocks.scala +++ b/src/compiler/scala/tools/nsc/backend/icode/BasicBlocks.scala @@ -300,14 +300,16 @@ trait BasicBlocks { if (!closed) instructionList = instructionList map (x => map.getOrElse(x, x)) else - instrs.zipWithIndex collect { - case (oldInstr, i) if map contains oldInstr => - // SI-6288 clone important here because `replaceInstruction` assigns - // a position to `newInstr`. Without this, a single instruction can - // be added twice, and the position last position assigned clobbers - // all previous positions in other usages. - val newInstr = map(oldInstr).clone() - code.touched |= replaceInstruction(i, newInstr) + instrs.iterator.zipWithIndex foreach { + case (oldInstr, i) => + if (map contains oldInstr) { + // SI-6288 clone important here because `replaceInstruction` assigns + // a position to `newInstr`. Without this, a single instruction can + // be added twice, and the position last position assigned clobbers + // all previous positions in other usages. + val newInstr = map(oldInstr).clone() + code.touched |= replaceInstruction(i, newInstr) + } } ////////////////////// Emit ////////////////////// |