diff options
author | michelou <michelou@epfl.ch> | 2008-02-22 15:23:15 +0000 |
---|---|---|
committer | michelou <michelou@epfl.ch> | 2008-02-22 15:23:15 +0000 |
commit | bb37eb067be49ed9f7b070a7cab354801c38f9ad (patch) | |
tree | e3081526b2ec16da0399d1c37226f8a3da0835e2 /src | |
parent | ae85da1eacee620e4d33e048715f52a9aa34b426 (diff) | |
download | scala-bb37eb067be49ed9f7b070a7cab354801c38f9ad.tar.gz scala-bb37eb067be49ed9f7b070a7cab354801c38f9ad.tar.bz2 scala-bb37eb067be49ed9f7b070a7cab354801c38f9ad.zip |
fixed #468
Diffstat (limited to 'src')
-rw-r--r-- | src/compiler/scala/tools/nsc/backend/msil/GenMSIL.scala | 22 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/backend/opt/DeadCodeElimination.scala | 4 | ||||
-rw-r--r-- | src/library/scala/List.scala | 55 |
3 files changed, 63 insertions, 18 deletions
diff --git a/src/compiler/scala/tools/nsc/backend/msil/GenMSIL.scala b/src/compiler/scala/tools/nsc/backend/msil/GenMSIL.scala index ed7e1cefc8..23cc7b94e1 100644 --- a/src/compiler/scala/tools/nsc/backend/msil/GenMSIL.scala +++ b/src/compiler/scala/tools/nsc/backend/msil/GenMSIL.scala @@ -1,5 +1,5 @@ /* NSC -- new scala compiler - * Copyright 2005-2007 LAMP/EPFL + * Copyright 2005-2008 LAMP/EPFL * @author Nikolay Mihaylov */ @@ -581,7 +581,7 @@ abstract class GenMSIL extends SubComponent { } if (mcode != null) { - for (local <- m.locals.diff(m.params)) { + for (local <- m.locals -- m.params) { if (settings.debug.value) log("add local var: " + local + ", of kind " + local.kind) val t: MsilType = msilType(local.kind) @@ -861,7 +861,7 @@ abstract class GenMSIL extends SubComponent { // problem: block may already be added, and and needs to be moved. // if nextblock NOT in b: check if nextblock in blocksToPut, if NOT, check if movable, else don't put if (nextBlock != null && b.contains(nextBlock)) { - val blocksToAdd = nextBlock :: b.diff(List(nextBlock)) + val blocksToAdd = nextBlock :: (b - nextBlock) nextBlock = null addBlocks(blocksToAdd) } @@ -874,7 +874,7 @@ abstract class GenMSIL extends SubComponent { { // the block is not part of some catch or finally code currentBlock.addBasicBlock(x) - blocksToPut = blocksToPut.diff(List(x)) + blocksToPut = blocksToPut - x if (settings.debug.value) log(" -> addBlocks(" + xs + ")") addBlocks(xs) } else { @@ -885,7 +885,7 @@ abstract class GenMSIL extends SubComponent { // is optimized by compiler (no try left) if(untreatedHandlers.forall(h => (!h.blocks.contains(x) || h.covered.isEmpty))) { - blocksToPut = blocksToPut.diff(List(x)) + blocksToPut = blocksToPut - x addBlocks(xs) } else addBlocks(xs ::: List(x)) @@ -981,7 +981,7 @@ abstract class GenMSIL extends SubComponent { //else () //assert(firstBlockAfter(exh) == outside(0), "try/catch leaving to multiple targets: " + firstBlockAfter(exh) + ", new: " + outside(0)) val last = leaving(0)._1 - (blocks.diff(List(last)) ::: List(last), None) + ((blocks - last) ::: List(last), None) } else { val outside = leaving.flatMap(p => p._2) //assert(outside.forall(b => b == outside(0)), "exception-block leaving to multiple targets") @@ -1003,7 +1003,7 @@ abstract class GenMSIL extends SubComponent { // shorter try-catch-finally last (the ones contained in another) affectedHandlers = affectedHandlers.sort({(h1, h2) => h1.covered.length > h2.covered.length}) affectedHandlers = affectedHandlers.filter(h => {h.covered.length == affectedHandlers(0).covered.length}) - untreatedHandlers = untreatedHandlers.diff(affectedHandlers) + untreatedHandlers = untreatedHandlers -- affectedHandlers // more than one catch produces more than one exh, but we only need one var singleAffectedHandler: ExceptionHandler = affectedHandlers(0) // List[ExceptionHandler] = Nil @@ -1017,7 +1017,7 @@ abstract class GenMSIL extends SubComponent { h1.addBlock(block) case None => () } - val orderedCatchBlocks = h1.startBlock :: adaptedBlocks.diff(List(h1.startBlock)) + val orderedCatchBlocks = h1.startBlock :: (adaptedBlocks - h1.startBlock) exceptionBlock match { case Some(excBlock) => @@ -1048,7 +1048,7 @@ abstract class GenMSIL extends SubComponent { singleAffectedHandler.finalizer.addBlock(block) case None => () } - val blocks = singleAffectedHandler.finalizer.startBlock :: blocks0.diff(List(singleAffectedHandler.finalizer.startBlock)) + val blocks = singleAffectedHandler.finalizer.startBlock :: (blocks0 - singleAffectedHandler.finalizer.startBlock) currentBlock = excBlock.finallyBlock addBlocks(blocks) } @@ -1148,7 +1148,7 @@ abstract class GenMSIL extends SubComponent { "untreated exception handlers left: " + untreatedHandlers) // remove catch blocks from empty handlers (finally-blocks remain) untreatedHandlers.foreach((h) => { - orderedBlocks = orderedBlocks.diff(h.blocks) + orderedBlocks = orderedBlocks -- h.blocks }) // take care of order in which exHInstructions are executed (BeginExceptionBlock as last) @@ -1810,7 +1810,7 @@ abstract class GenMSIL extends SubComponent { idx += 1 // sizeOf(l.kind) } - val locvars = m.locals.diff(params) + val locvars = m.locals -- params idx = 0 for (l <- locvars) { diff --git a/src/compiler/scala/tools/nsc/backend/opt/DeadCodeElimination.scala b/src/compiler/scala/tools/nsc/backend/opt/DeadCodeElimination.scala index b7cc9998cd..04b23ed493 100644 --- a/src/compiler/scala/tools/nsc/backend/opt/DeadCodeElimination.scala +++ b/src/compiler/scala/tools/nsc/backend/opt/DeadCodeElimination.scala @@ -83,8 +83,8 @@ abstract class DeadCodeElimination extends SubComponent { mark sweep(m) accessedLocals = accessedLocals.removeDuplicates - if (m.locals.diff(accessedLocals).length > 0) { - log("Removed dead locals: " + m.locals.diff(accessedLocals)) + if ((m.locals -- accessedLocals).length > 0) { + log("Removed dead locals: " + (m.locals -- accessedLocals)) m.locals = accessedLocals.reverse } } diff --git a/src/library/scala/List.scala b/src/library/scala/List.scala index 7d65d6d35c..b6086e2460 100644 --- a/src/library/scala/List.scala +++ b/src/library/scala/List.scala @@ -1,6 +1,6 @@ /* __ *\ ** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2003-2007, LAMP/EPFL ** +** / __/ __// _ | / / / _ | (c) 2003-2008, LAMP/EPFL ** ** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** ** /____/\___/_/ |_/____/_/ | | ** ** |/ ** @@ -436,14 +436,30 @@ sealed abstract class List[+A] extends Seq[A] { * Add an element <code>x</code> at the beginning of this list. * </p> * - * @param x the element to append. - * @return the list with <code>x</code> appended at the beginning. + * @param x the element to prepend. + * @return the list with <code>x</code> added at the beginning. * @ex <code>1 :: List(2, 3) = List(2, 3).::(1) = List(1, 2, 3)</code> */ def ::[B >: A] (x: B): List[B] = new scala.::(x, this) /** <p> + * Add an element <code>x</code> at the end of this list. + * </p> + * + * @param x the element to append. + * @return the list with <code>x</code> added at the end. + */ + def +[B >: A](x: B): List[B] = + if (isEmpty) List(x) + else { + val buf = new ListBuffer[B] + this copyToBuffer buf + buf += x + buf.toList + } + + /** <p> * Returns a list resulting from the concatenation of the given * list <code>prefix</code> and this list. * </p> @@ -464,6 +480,15 @@ sealed abstract class List[+A] extends Seq[A] { b.prependToList(this) } + /** Appends two list objects. + */ + override def ++[B >: A](that: Iterable[B]): List[B] = { + val buf = new ListBuffer[B] + this copyToBuffer buf + that copyToBuffer buf + buf.toList + } + /** Reverse the given prefix and append the current list to that. * This function is equivalent to an application of <code>reverse</code> * on the prefix followed by a call to <code>:::</code>, but more @@ -1168,8 +1193,19 @@ sealed abstract class List[+A] extends Seq[A] { * @param that the list of elements to remove from this list. * @return this list without the elements of the given list * <code>that</code>. + * @deprecated use <code>--</code> instead */ - def diff[B >: A](that: List[B]): List[B] = { + @deprecated + def diff[B >: A](that: List[B]): List[B] = this -- that + + /** Computes the difference between this list and the given list + * <code>that</code>. + * + * @param that the list of elements to remove from this list. + * @return this list without the elements of the given list + * <code>that</code>. + */ + def -- [B >: A](that: List[B]): List[B] = { val b = new ListBuffer[B] var these = this while (!these.isEmpty) { @@ -1179,13 +1215,22 @@ sealed abstract class List[+A] extends Seq[A] { b.toList } + /** Computes the difference between this list and the given object + * <code>x</code>. + * + * @param x the object to remove from this list. + * @return this list without the elements of the given object + * <code>x</code>. + */ + def - [B >: A](x: B): List[B] = + this -- List(x) + def flatten[B](implicit f : A => Iterable[B]) : List[B] = { val buf = new ListBuffer[B] foreach(f(_).foreach(buf += _)) buf.toList } - /** Computes the intersection between this list and the given list * <code>that</code>. * |