summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2010-12-20 06:38:16 +0000
committerPaul Phillips <paulp@improving.org>2010-12-20 06:38:16 +0000
commitf40a20b0f418209715529ca5b373f641a5011e0b (patch)
tree64e8462fc2d0ddb6fc4192f64e73a628d8a4ae3e /src
parent0e306e1f90f51efa2d423fd7df810f7cc8dfa915 (diff)
downloadscala-f40a20b0f418209715529ca5b373f641a5011e0b.tar.gz
scala-f40a20b0f418209715529ca5b373f641a5011e0b.tar.bz2
scala-f40a20b0f418209715529ca5b373f641a5011e0b.zip
I'm wandering around trunk looking for slowness.
are constant distractions which I've meant forever to fix anyway, such as the importing of collection.mutable._ (or any other package with lots of reused names.) Why is this relevant to performance? Well, var x = new HashSet[Int] What's that? What does 'x += 1' mean? These are questions we can all live without. There's almost nothing left which references HashSet or HashMap or Stack or other ambiguous classes without a qualifier: I can finish trunk but I can't keep it clean on my own. (Where should I be writing this stuff down, I wonder.) No review.
Diffstat (limited to 'src')
-rw-r--r--src/compiler/scala/tools/nsc/ast/TreePrinters.scala17
-rw-r--r--src/compiler/scala/tools/nsc/backend/icode/BasicBlocks.scala2
-rw-r--r--src/compiler/scala/tools/nsc/backend/icode/GenICode.scala10
-rw-r--r--src/compiler/scala/tools/nsc/backend/icode/ICodes.scala3
-rw-r--r--src/compiler/scala/tools/nsc/backend/icode/Linearizers.scala50
-rw-r--r--src/compiler/scala/tools/nsc/backend/icode/analysis/ReachingDefinitions.scala9
-rw-r--r--src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala4
-rw-r--r--src/compiler/scala/tools/nsc/backend/opt/Inliners.scala32
-rw-r--r--src/compiler/scala/tools/nsc/symtab/classfile/ICodeReader.scala21
-rw-r--r--src/library/scala/LowPriorityImplicits.scala15
-rw-r--r--src/library/scala/collection/immutable/HashMap.scala1
-rw-r--r--src/library/scala/collection/immutable/HashSet.scala1
-rw-r--r--src/library/scala/mobile/Location.scala53
-rw-r--r--src/library/scala/util/parsing/combinator/PackratParsers.scala13
-rw-r--r--src/scalap/scala/tools/scalap/Arguments.scala96
-rw-r--r--src/swing/scala/swing/Menu.scala6
16 files changed, 120 insertions, 213 deletions
diff --git a/src/compiler/scala/tools/nsc/ast/TreePrinters.scala b/src/compiler/scala/tools/nsc/ast/TreePrinters.scala
index 0df9bbed57..a51bd8e9b3 100644
--- a/src/compiler/scala/tools/nsc/ast/TreePrinters.scala
+++ b/src/compiler/scala/tools/nsc/ast/TreePrinters.scala
@@ -6,7 +6,6 @@
package scala.tools.nsc
package ast
-import compat.Platform.{EOL => LINE_SEPARATOR}
import java.io.{ OutputStream, PrintWriter, StringWriter, Writer }
import symtab.Flags._
import symtab.SymbolTable
@@ -435,13 +434,12 @@ trait TreePrinters { trees: SymbolTable =>
}
def print(unit: CompilationUnit) {
- print("// Scala source: " + unit.source + LINE_SEPARATOR)
- if (unit.body ne null) {
- print(unit.body); println()
- } else {
- print("<null>")
- }
- println(); flush
+ print("// Scala source: " + unit.source + "\n")
+ if (unit.body == null) print("<null>")
+ else { print(unit.body); println() }
+
+ println()
+ flush()
}
}
@@ -695,8 +693,7 @@ trait TreePrinters { trees: SymbolTable =>
override def write(str: String) { Console.print(str) }
def write(cbuf: Array[Char], off: Int, len: Int) {
- val str = new String(cbuf, off, len)
- write(str)
+ write(new String(cbuf, off, len))
}
def close = { /* do nothing */ }
diff --git a/src/compiler/scala/tools/nsc/backend/icode/BasicBlocks.scala b/src/compiler/scala/tools/nsc/backend/icode/BasicBlocks.scala
index c7cdad7c20..dbc8c106f3 100644
--- a/src/compiler/scala/tools/nsc/backend/icode/BasicBlocks.scala
+++ b/src/compiler/scala/tools/nsc/backend/icode/BasicBlocks.scala
@@ -303,7 +303,7 @@ trait BasicBlocks {
/** Close the block */
def close {
assert(!closed || ignore)
- assert(instructionList.length > 0, "Empty block.")
+ assert(instructionList.nonEmpty, "Empty block.")
closed = true
setFlag(DIRTYSUCCS)
instructionList = instructionList.reverse
diff --git a/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala b/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala
index 0e2c39aeee..50bb26d491 100644
--- a/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala
+++ b/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala
@@ -9,7 +9,7 @@ package backend
package icode
import scala.collection.{ mutable, immutable }
-import scala.collection.mutable.{ HashMap, ListBuffer, Buffer, HashSet }
+import scala.collection.mutable.{ ListBuffer, Buffer }
import scala.tools.nsc.symtab._
import scala.annotation.switch
import PartialFunction._
@@ -1757,7 +1757,7 @@ abstract class GenICode extends SubComponent {
* to delay it any more: they will be used at some point.
*/
class DuplicateLabels(boundLabels: Set[Symbol]) extends Transformer {
- val labels: mutable.Map[Symbol, Symbol] = new HashMap
+ val labels: mutable.Map[Symbol, Symbol] = new mutable.HashMap
var method: Symbol = _
var ctx: Context = _
@@ -1835,7 +1835,7 @@ abstract class GenICode extends SubComponent {
var bb: BasicBlock = _
/** Map from label symbols to label objects. */
- var labels: HashMap[Symbol, Label] = new HashMap()
+ var labels = mutable.HashMap[Symbol, Label]()
/** Current method definition. */
var defdef: DefDef = _
@@ -1939,7 +1939,7 @@ abstract class GenICode extends SubComponent {
*/
def enterMethod(m: IMethod, d: DefDef): Context = {
val ctx1 = new Context(this) setMethod(m)
- ctx1.labels = new HashMap()
+ ctx1.labels = new mutable.HashMap()
ctx1.method.code = new Code(m.symbol.simpleName.toString(), m)
ctx1.bb = ctx1.method.code.startBlock
ctx1.defdef = d
@@ -1953,7 +1953,7 @@ abstract class GenICode extends SubComponent {
val block = method.code.newBlock
handlers foreach (_ addCoveredBlock block)
currentExceptionHandlers foreach (_ addBlock block)
- block.varsInScope = new HashSet() ++= scope.varsInScope
+ block.varsInScope = new mutable.HashSet() ++= scope.varsInScope
new Context(this) setBasicBlock block
}
diff --git a/src/compiler/scala/tools/nsc/backend/icode/ICodes.scala b/src/compiler/scala/tools/nsc/backend/icode/ICodes.scala
index dc31edc569..227ba36426 100644
--- a/src/compiler/scala/tools/nsc/backend/icode/ICodes.scala
+++ b/src/compiler/scala/tools/nsc/backend/icode/ICodes.scala
@@ -13,8 +13,7 @@ package backend
package icode
import java.io.PrintWriter
-
-import scala.collection.{ mutable, immutable, generic }
+import scala.collection.mutable
import scala.tools.nsc.symtab._
import analysis.{ Liveness, ReachingDefinitions }
import scala.tools.nsc.symtab.classfile.ICodeReader
diff --git a/src/compiler/scala/tools/nsc/backend/icode/Linearizers.scala b/src/compiler/scala/tools/nsc/backend/icode/Linearizers.scala
index 05259772f4..aaf8037768 100644
--- a/src/compiler/scala/tools/nsc/backend/icode/Linearizers.scala
+++ b/src/compiler/scala/tools/nsc/backend/icode/Linearizers.scala
@@ -6,10 +6,11 @@
package scala.tools.nsc
package backend
-package icode;
+package icode
import scala.tools.nsc.ast._
-import scala.collection.mutable.{Stack, HashSet, BitSet, ListBuffer}
+import scala.collection.{ mutable, immutable }
+import mutable.ListBuffer
trait Linearizers { self: ICodes =>
import opcodes._;
@@ -29,7 +30,7 @@ trait Linearizers { self: ICodes =>
class NormalLinearizer extends Linearizer with WorklistAlgorithm {
type Elem = BasicBlock;
- val worklist: WList = new Stack();
+ val worklist: WList = new mutable.Stack();
var blocks: List[BasicBlock] = Nil;
@@ -126,9 +127,7 @@ trait Linearizers { self: ICodes =>
* @return Returns true if the block was added.
*/
def add(b: BasicBlock): Boolean =
- if (blocks.contains(b))
- false
- else {
+ !(blocks contains b) && {
blocks = b :: blocks;
true
}
@@ -140,13 +139,13 @@ trait Linearizers { self: ICodes =>
* This way, it is constructed already in reverse post order.
*/
class ReversePostOrderLinearizer extends Linearizer {
- var blocks: List[BasicBlock] = Nil;
- var visited: HashSet[BasicBlock] = new HashSet;
- val added: BitSet = new BitSet
+ var blocks: List[BasicBlock] = Nil
+ val visited = new mutable.HashSet[BasicBlock]
+ val added = new mutable.BitSet
def linearize(m: IMethod): List[BasicBlock] = {
blocks = Nil;
- visited.clear;
+ visited.clear()
added.clear;
m.exh foreach (b => rpo(b.startBlock));
@@ -162,18 +161,18 @@ trait Linearizers { self: ICodes =>
def linearizeAt(m: IMethod, start: BasicBlock): List[BasicBlock] = {
blocks = Nil
- visited.clear
- added.clear
+ visited.clear()
+ added.clear()
rpo(start)
blocks
}
def rpo(b: BasicBlock): Unit =
- if (b.size > 0 && !(visited contains b)) {
+ if (b.nonEmpty && !visited(b)) {
visited += b;
- b.successors foreach rpo;
- add(b);
+ b.successors foreach rpo
+ add(b)
}
/**
@@ -192,12 +191,8 @@ trait Linearizers { self: ICodes =>
* the last instruction being a jump).
*/
class DumpLinearizer extends Linearizer {
- def linearize(m: IMethod): List[BasicBlock] =
- m.code.blocks.toList;
-
- def linearizeAt(m: IMethod, start: BasicBlock): List[BasicBlock] = {
- system.error("not implemented")
- }
+ def linearize(m: IMethod): List[BasicBlock] = m.code.blocks.toList
+ def linearizeAt(m: IMethod, start: BasicBlock): List[BasicBlock] = system.error("not implemented")
}
/** The MSIL linearizer is used only for methods with at least one exception handler.
@@ -238,10 +233,9 @@ trait Linearizers { self: ICodes =>
}
val tryBlocks = handlersByCovered.keys.toList sortBy size
+ var result = normalLinearizer.linearize(m)
+ val frozen = mutable.HashSet[BasicBlock](result.head)
- var result = normalLinearizer.linearize(m)
-
- val frozen = HashSet[BasicBlock](result.head)
for (tryBlock <- tryBlocks) {
result = groupBlocks(m, result, handlersByCovered(tryBlock), frozen)
}
@@ -251,7 +245,7 @@ trait Linearizers { self: ICodes =>
/** @param handlers a list of handlers covering the same blocks (same try, multiple catches)
* @param frozen blocks can't be moved (fist block of a method, blocks directly following a try-catch)
*/
- def groupBlocks(method: IMethod, blocks: List[BasicBlock], handlers: List[ExceptionHandler], frozen: HashSet[BasicBlock]) = {
+ def groupBlocks(method: IMethod, blocks: List[BasicBlock], handlers: List[ExceptionHandler], frozen: mutable.HashSet[BasicBlock]) = {
assert(blocks.head == method.code.startBlock, method)
// blocks before the try, and blocks for the try
@@ -281,7 +275,7 @@ trait Linearizers { self: ICodes =>
}
// reorder the blocks in "catches" so that the "firstBlock" is actually first
- for ((lb, handler) <- catches.zip(handlers)) {
+ (catches, handlers).zipped foreach { (lb, handler) =>
lb -= handler.startBlock
handler.startBlock +=: lb
}
@@ -305,7 +299,7 @@ trait Linearizers { self: ICodes =>
}
if (firstAfter.isDefined) {
val b = firstAfter.get
- if (frozen contains b) {
+ if (frozen(b)) {
assert(after contains b, b +", "+ method)
} else {
frozen += b
@@ -328,7 +322,7 @@ trait Linearizers { self: ICodes =>
* that list, i.e. successors outside the `blocks` list.
*/
private def leavingBlocks(blocks: List[BasicBlock]) = {
- val res = new HashSet[BasicBlock]()
+ val res = new mutable.HashSet[BasicBlock]()
for (b <- blocks; s <- b.directSuccessors; if (!blocks.contains(s)))
res += s
res
diff --git a/src/compiler/scala/tools/nsc/backend/icode/analysis/ReachingDefinitions.scala b/src/compiler/scala/tools/nsc/backend/icode/analysis/ReachingDefinitions.scala
index d7e5e84a80..c18408ddbd 100644
--- a/src/compiler/scala/tools/nsc/backend/icode/analysis/ReachingDefinitions.scala
+++ b/src/compiler/scala/tools/nsc/backend/icode/analysis/ReachingDefinitions.scala
@@ -10,7 +10,6 @@ package analysis
import scala.collection.{ mutable, immutable }
import immutable.ListSet
-import mutable.HashMap
/** Compute reaching definitions. We are only interested in reaching
* definitions for local variables, since values on the stack
@@ -69,10 +68,10 @@ abstract class ReachingDefinitions {
var method: IMethod = _
- val gen: mutable.Map[BasicBlock, Set[Definition]] = new HashMap()
- val kill: mutable.Map[BasicBlock, Set[Local]] = new HashMap()
- val drops: mutable.Map[BasicBlock, Int] = new HashMap()
- val outStack: mutable.Map[BasicBlock, Stack] = new HashMap()
+ val gen: mutable.Map[BasicBlock, Set[Definition]] = new mutable.HashMap()
+ val kill: mutable.Map[BasicBlock, Set[Local]] = new mutable.HashMap()
+ val drops: mutable.Map[BasicBlock, Int] = new mutable.HashMap()
+ val outStack: mutable.Map[BasicBlock, Stack] = new mutable.HashMap()
def init(m: IMethod) {
this.method = m
diff --git a/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala b/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala
index 41df23427b..8a09009ad2 100644
--- a/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala
+++ b/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala
@@ -1008,7 +1008,7 @@ abstract class GenJVM extends SubComponent with GenJVMUtil with GenAndroid {
linearization = linearizer.linearize(m)
val labels = makeLabels(linearization)
/** local variables whose scope appears in this block. */
- var varsInBlock: mutable.Set[Local] = new mutable.HashSet
+ val varsInBlock: mutable.Set[Local] = new mutable.HashSet
var nextBlock: BasicBlock = linearization.head
@@ -1085,7 +1085,7 @@ abstract class GenJVM extends SubComponent with GenJVMUtil with GenAndroid {
var lastMappedPC = 0
var lastLineNr = 0
var crtPC = 0
- varsInBlock.clear
+ varsInBlock.clear()
for (instr <- b) {
class CompilationException(msg: String) extends Exception(msg) {
diff --git a/src/compiler/scala/tools/nsc/backend/opt/Inliners.scala b/src/compiler/scala/tools/nsc/backend/opt/Inliners.scala
index 9b7bb3444a..acb4274cb2 100644
--- a/src/compiler/scala/tools/nsc/backend/opt/Inliners.scala
+++ b/src/compiler/scala/tools/nsc/backend/opt/Inliners.scala
@@ -7,9 +7,7 @@
package scala.tools.nsc
package backend.opt
-import scala.util.control.Breaks._
-import scala.collection.{ mutable, immutable }
-import mutable.{ HashMap, HashSet }
+import scala.collection.mutable
import scala.tools.nsc.symtab._
/**
@@ -80,17 +78,15 @@ abstract class Inliners extends SubComponent {
val Public, Protected, Private = Value
/** Cache whether a method calls private members. */
- val usesNonPublics: mutable.Map[IMethod, Value] = new HashMap
+ val usesNonPublics: mutable.Map[IMethod, Value] = new mutable.HashMap
}
import NonPublicRefs._
/* fresh name counter */
- val fresh = new HashMap[String, Int]
- var count = 0
+ val fresh = new mutable.HashMap[String, Int] withDefaultValue 0
def freshName(s: String) = {
- val count = fresh.getOrElseUpdate(s, 0)
fresh(s) += 1
- s + count
+ s + fresh(s)
}
private def hasInline(sym: Symbol) = sym hasAnnotation ScalaInlineClass
@@ -110,10 +106,10 @@ abstract class Inliners extends SubComponent {
}
val tfa = new analysis.MethodTFA()
- tfa.stat = settings.Ystatistics.value
+ tfa.stat = global.opt.printStats
// how many times have we already inlined this method here?
- private val inlinedMethodCount: mutable.Map[Symbol, Int] = new HashMap[Symbol, Int] {
+ private val inlinedMethodCount: mutable.Map[Symbol, Int] = new mutable.HashMap[Symbol, Int] {
override def default(k: Symbol) = 0
}
@@ -122,8 +118,8 @@ abstract class Inliners extends SubComponent {
var instrBeforeInlining = if (m.code ne null) m.code.blocks.foldLeft(0)(_ + _.length) else 0
var retry = false
var count = 0
- fresh.clear
- inlinedMethodCount.clear
+ fresh.clear()
+ inlinedMethodCount.clear()
val caller = new IMethodInfo(m)
var info: tfa.lattice.Elem = null
@@ -218,7 +214,6 @@ abstract class Inliners extends SubComponent {
i match {
case CALL_METHOD(msym, Dynamic) =>
if (analyzeInc(msym, i, bb)) break
-
case _ => ()
}
info = tfa.interpret(info, i)
@@ -342,9 +337,9 @@ abstract class Inliners extends SubComponent {
val activeHandlers = caller.handlers filter (_ covered block)
/* Map 'original' blocks to the ones inlined in the caller. */
- val inlinedBlock: mutable.Map[BasicBlock, BasicBlock] = new HashMap
+ val inlinedBlock: mutable.Map[BasicBlock, BasicBlock] = new mutable.HashMap
- val varsInScope: mutable.Set[Local] = HashSet() ++= block.varsInScope
+ val varsInScope: mutable.Set[Local] = mutable.HashSet() ++= block.varsInScope
/** Side effects varsInScope when it sees SCOPE_ENTERs. */
def instrBeforeFilter(i: Instruction): Boolean = {
@@ -365,7 +360,7 @@ abstract class Inliners extends SubComponent {
case x => newLocal("$retVal", x)
}
- val inlinedLocals: mutable.Map[Local, Local] = new HashMap
+ val inlinedLocals: mutable.Map[Local, Local] = new mutable.HashMap
/** Add a new block in the current context. */
def newBlock() = {
@@ -386,7 +381,7 @@ abstract class Inliners extends SubComponent {
/** alfa-rename `l' in caller's context. */
def dupLocal(l: Local): Local = {
- val sym = caller.sym.newVariable(l.sym.pos, freshName(l.sym.name.toString()))
+ val sym = caller.sym.newVariable(l.sym.pos, freshName(l.sym.name.toString))
// sym.setInfo(l.sym.tpe)
val dupped = new Local(sym, l.kind, false)
inlinedLocals(l) = dupped
@@ -396,7 +391,7 @@ abstract class Inliners extends SubComponent {
val afterBlock = newBlock()
/** Map from nw.init instructions to their matching NEW call */
- val pending: mutable.Map[Instruction, NEW] = new HashMap
+ val pending: mutable.Map[Instruction, NEW] = new mutable.HashMap
/** Map an instruction from the callee to one suitable for the caller. */
def map(i: Instruction): Instruction = {
@@ -488,7 +483,6 @@ abstract class Inliners extends SubComponent {
afterBlock emit instrAfter
afterBlock.close
- count += 1
// add exception handlers of the callee
caller addHandlers (inc.handlers map translateExh)
diff --git a/src/compiler/scala/tools/nsc/symtab/classfile/ICodeReader.scala b/src/compiler/scala/tools/nsc/symtab/classfile/ICodeReader.scala
index 95d278a7a5..1d8df4fa02 100644
--- a/src/compiler/scala/tools/nsc/symtab/classfile/ICodeReader.scala
+++ b/src/compiler/scala/tools/nsc/symtab/classfile/ICodeReader.scala
@@ -7,13 +7,11 @@ package scala.tools.nsc
package symtab
package classfile
-import java.io.IOException
-
-import scala.collection.mutable._
+import scala.collection.{ mutable, immutable }
+import mutable.ListBuffer
import scala.tools.nsc._
import scala.tools.nsc.backend.icode._
import scala.tools.nsc.io._
-
import ClassfileConstants._
import Flags._
@@ -665,8 +663,8 @@ abstract class ICodeReader extends ClassfileParser {
class LinearCode {
var instrs: ListBuffer[(Int, Instruction)] = new ListBuffer
- var jmpTargets: Set[Int] = new HashSet[Int]
- var locals: Map[Int, List[(Local, TypeKind)]] = new HashMap()
+ var jmpTargets: mutable.Set[Int] = new mutable.HashSet[Int]
+ var locals: mutable.Map[Int, List[(Local, TypeKind)]] = new mutable.HashMap()
var containsDUPX = false
var containsNEW = false
@@ -689,11 +687,8 @@ abstract class ICodeReader extends ClassfileParser {
method.setCode(code)
var bb = code.startBlock
- def makeBasicBlocks: Map[Int, BasicBlock] = {
- val block: Map[Int, BasicBlock] = new HashMap
- for (pc <- jmpTargets) block += (pc -> code.newBlock)
- block
- }
+ def makeBasicBlocks: mutable.Map[Int, BasicBlock] =
+ mutable.Map(jmpTargets.toSeq map (_ -> code.newBlock): _*)
val blocks = makeBasicBlocks
var otherBlock: BasicBlock = null
@@ -701,7 +696,7 @@ abstract class ICodeReader extends ClassfileParser {
for ((pc, instr) <- instrs.iterator) {
// Console.println("> " + pc + ": " + instr);
- if (jmpTargets contains pc) {
+ if (jmpTargets(pc)) {
otherBlock = blocks(pc)
if (!bb.closed && otherBlock != bb) {
bb.emit(JUMP(otherBlock))
@@ -1054,7 +1049,7 @@ abstract class ICodeReader extends ClassfileParser {
case class LSWITCH(tags: List[List[Int]], targets: List[Int]) extends LazyJump(targets.head) {
override def toString(): String ="LSWITCH (tags: " + tags + ") targets: " + targets;
- targets.tail.foreach(t => jmpTargets += t)
+ jmpTargets ++= targets.tail
}
/** Duplicate and exchange pseudo-instruction. Should be later
diff --git a/src/library/scala/LowPriorityImplicits.scala b/src/library/scala/LowPriorityImplicits.scala
index d6a46ff1aa..0182ecdae9 100644
--- a/src/library/scala/LowPriorityImplicits.scala
+++ b/src/library/scala/LowPriorityImplicits.scala
@@ -8,9 +8,10 @@
package scala
-import collection.mutable._
-import collection.immutable.WrappedString
-import collection.generic.CanBuildFrom
+import scala.collection.{ mutable, immutable, generic }
+import mutable.WrappedArray
+import immutable.WrappedString
+import generic.CanBuildFrom
/** The `LowPriorityImplicits` class provides implicit values that
* are valid in all Scala compilation units without explicit qualification,
@@ -52,10 +53,10 @@ class LowPriorityImplicits {
implicit def wrapString(s: String): WrappedString = if (s ne null) new WrappedString(s) else null
implicit def unwrapString(ws: WrappedString): String = if (ws ne null) ws.self else null
- implicit def fallbackStringCanBuildFrom[T]: CanBuildFrom[String, T, collection.immutable.IndexedSeq[T]] =
- new CanBuildFrom[String, T, collection.immutable.IndexedSeq[T]] {
- def apply(from: String) = scala.collection.immutable.IndexedSeq.newBuilder[T]
- def apply() = scala.collection.immutable.IndexedSeq.newBuilder[T]
+ implicit def fallbackStringCanBuildFrom[T]: CanBuildFrom[String, T, immutable.IndexedSeq[T]] =
+ new CanBuildFrom[String, T, immutable.IndexedSeq[T]] {
+ def apply(from: String) = immutable.IndexedSeq.newBuilder[T]
+ def apply() = immutable.IndexedSeq.newBuilder[T]
}
}
diff --git a/src/library/scala/collection/immutable/HashMap.scala b/src/library/scala/collection/immutable/HashMap.scala
index e0d57b019e..5b20638a84 100644
--- a/src/library/scala/collection/immutable/HashMap.scala
+++ b/src/library/scala/collection/immutable/HashMap.scala
@@ -320,7 +320,6 @@ object HashMap extends ImmutableMapFactory[HashMap] {
/*
-import collection.immutable._
def time(block: =>Unit) = { val t0 = System.nanoTime; block; println("elapsed: " + (System.nanoTime - t0)/1000000.0) }
var mOld = OldHashMap.empty[Int,Int]
var mNew = HashMap.empty[Int,Int]
diff --git a/src/library/scala/collection/immutable/HashSet.scala b/src/library/scala/collection/immutable/HashSet.scala
index 8868344803..6164b96634 100644
--- a/src/library/scala/collection/immutable/HashSet.scala
+++ b/src/library/scala/collection/immutable/HashSet.scala
@@ -255,7 +255,6 @@ object HashSet extends ImmutableSetFactory[HashSet] {
/*
-import collection.immutable._
def time(block: =>Unit) = { val t0 = System.nanoTime; block; println("elapsed: " + (System.nanoTime - t0)/1000000.0) }
var mOld = OldHashSet.empty[Int]
var mNew = HashSet.empty[Int]
diff --git a/src/library/scala/mobile/Location.scala b/src/library/scala/mobile/Location.scala
index 4b5f13111d..b5cce13deb 100644
--- a/src/library/scala/mobile/Location.scala
+++ b/src/library/scala/mobile/Location.scala
@@ -6,15 +6,10 @@
** |/ **
\* */
-
-
package scala.mobile
-
-import java.lang.ClassLoader
import java.net._
-
-import scala.collection.mutable._
+import scala.collection.mutable
/** The class <code>Location</code> provides a <code>create</code>
* method to instantiate objects from a network location by
@@ -33,56 +28,34 @@ import scala.collection.mutable._
* @version 1.0, 04/05/2004
*/
class Location(url: URL) {
-
/** A cache containing all class loaders of this location.
*/
- private var lcache: Map[URL, ClassLoader] = new HashMap
+ private val lcache = new mutable.HashMap[URL, ClassLoader]
/** The class loader associated with this location.
*/
- private val loader = if (url eq null)
- ClassLoader.getSystemClassLoader()
- else
- lcache.get(url) match {
- case Some(cl) =>
- cl
- case _ =>
- val cl = new URLClassLoader(Array(url))
- lcache(url) = cl
- cl
- }
+ private val loader =
+ if (url eq null) ClassLoader.getSystemClassLoader()
+ else lcache.getOrElseUpdate(url, new URLClassLoader(Array(url)))
/** A cache containing all classes of this location.
*/
- private var ccache: Map[String, java.lang.Class[T] forSome { type T }] = new HashMap
+ private val ccache = new mutable.HashMap[String, java.lang.Class[_]]
/** Return the code description for the string <code>className</code>
* at this location.
*
* @param classname the name of the class
- * @return the code description corresponding to
- * <code>className</code>.
+ * @return the code description corresponding to `className`.
*/
def create(className: String) = new Code(
- ccache.get(className) match {
- case Some(clazz) =>
- clazz
- case _ =>
- val clazz = if (loader.loadClass(className).isInterface()) {
- // Scala source: class A { ... };
- // Java bytecode: interface A.class + class A$class.class
- loader.loadClass(className + "$class")
- }
- else {
- // Scala source: object A { ... };
- // Java bytecode: interface A.class + class A$.class
- loader.loadClass(className + "$")
- }
- ccache(className) = clazz
- clazz
- }
+ ccache.getOrElseUpdate(className, {
+ // source 'class A { ... }' becomes in bytecode: interface A.class + class A$class.class
+ // source 'object A { ... }' becomes in bytecode: interface A.class + class A$.class
+ val append = if (loader.loadClass(className).isInterface) "$class" else "$"
+ loader loadClass (className + append)
+ })
)
-
}
/** The object <code>Location</code> can be used to instantiate
diff --git a/src/library/scala/util/parsing/combinator/PackratParsers.scala b/src/library/scala/util/parsing/combinator/PackratParsers.scala
index 1e2975b615..6758ecfd3b 100644
--- a/src/library/scala/util/parsing/combinator/PackratParsers.scala
+++ b/src/library/scala/util/parsing/combinator/PackratParsers.scala
@@ -9,10 +9,9 @@
package scala.util.parsing.combinator
-import scala.collection.mutable._
import scala.util.parsing.combinator._
-import scala.util.parsing.input.Position
-import scala.util.parsing.input.Reader
+import scala.util.parsing.input.{ Reader, Position }
+import scala.collection.mutable
/**
* <p>
@@ -69,8 +68,7 @@ trait PackratParsers extends Parsers {
* caching of intermediate parse results and information about recursion
*/
- private[PackratParsers] val cache: HashMap[(Parser[_], Position), MemoEntry[_]] = HashMap.empty
-
+ private[PackratParsers] val cache = mutable.HashMap.empty[(Parser[_], Position), MemoEntry[_]]
private[PackratParsers] def getFromCache[T](p: Parser[T]): Option[MemoEntry[T]] = {
cache.get((p, pos)).asInstanceOf[Option[MemoEntry[T]]]
@@ -83,14 +81,11 @@ trait PackratParsers extends Parsers {
/* a cache for storing parser heads: allows to know which parser is involved
in a recursion*/
- private[PackratParsers] val recursionHeads: HashMap[Position, Head] = HashMap.empty
+ private[PackratParsers] val recursionHeads: mutable.HashMap[Position, Head] = mutable.HashMap.empty
//a stack that keeps a list of all involved rules
private[PackratParsers] var lrStack: List[LR] = Nil
-
-
-
override def source: java.lang.CharSequence = underlying.source
override def offset: Int = underlying.offset
diff --git a/src/scalap/scala/tools/scalap/Arguments.scala b/src/scalap/scala/tools/scalap/Arguments.scala
index ebe3d972f0..a364b54120 100644
--- a/src/scalap/scala/tools/scalap/Arguments.scala
+++ b/src/scalap/scala/tools/scalap/Arguments.scala
@@ -8,18 +8,16 @@
package scala.tools.scalap
-import scala.collection.mutable._
-
+import scala.collection.mutable
+import mutable.{ Buffer, ListBuffer }
object Arguments {
-
case class Parser(optionPrefix: Char) {
-
- val options: Set[String] = new HashSet
- val prefixes: Set[String] = new HashSet
- val optionalArgs: Set[String] = new HashSet
- val prefixedBindings: Map[String, Char] = new HashMap
- val optionalBindings: Map[String, Char] = new HashMap
+ val options: mutable.Set[String] = new mutable.HashSet
+ val prefixes: mutable.Set[String] = new mutable.HashSet
+ val optionalArgs: mutable.Set[String] = new mutable.HashSet
+ val prefixedBindings: mutable.Map[String, Char] = new mutable.HashMap
+ val optionalBindings: mutable.Map[String, Char] = new mutable.HashMap
def argumentError(message: String): Unit = Console.println(message)
@@ -48,14 +46,9 @@ object Arguments {
this
}
- def parseBinding(str: String, separator: Char): (String, String) = {
- val eqls = str.indexOf(separator)
- if (eqls < 0) {
- argumentError("missing '" + separator + "' in binding '" + str + "'")
- Pair("", "")
- } else
- Pair(str.substring(0, eqls).trim(),
- str.substring(eqls + 1).trim())
+ def parseBinding(str: String, separator: Char): (String, String) = (str indexOf separator) match {
+ case -1 => argumentError("missing '" + separator + "' in binding '" + str + "'") ; Pair("", "")
+ case idx => Pair(str take idx trim, str drop (idx + 1) trim)
}
def parse(args: Array[String]): Arguments = {
@@ -73,7 +66,7 @@ object Arguments {
else if (args(i).charAt(0) != optionPrefix) {
res.addOther(args(i))
i += 1
- } else if (options contains args(i)) {
+ } else if (options(args(i))) {
res.addOption(args(i))
i += 1
} else if (optionalArgs contains args(i)) {
@@ -126,78 +119,49 @@ object Arguments {
def parse(options: String*)(args: Array[String]): Arguments = {
val parser = new Parser('-')
- val iter = options.iterator
- while (iter.hasNext)
- parser withOption iter.next
- parser.parse(args)
+ options foreach (parser withOption _)
+ parser parse args
}
}
class Arguments {
-
- private val options: Set[String] = new HashSet
- private val arguments: Map[String, String] = new HashMap
- private val prefixes: Map[String, Set[String]] = new HashMap
- private val bindings: Map[String, Map[String, String]] = new HashMap
- private val others: Buffer[String] = new ListBuffer
+ private val options = new mutable.HashSet[String]
+ private val arguments = new mutable.HashMap[String, String]
+ private val prefixes = new mutable.HashMap[String, mutable.HashSet[String]]
+ private val bindings = new mutable.HashMap[String, mutable.HashMap[String, String]]
+ private val others = new ListBuffer[String]
def addOption(option: String): Unit = options += option
- def addArgument(option: String, arg: String) {
- arguments(option) = arg
- }
+ def addArgument(option: String, arg: String): Unit = arguments(option) = arg
def addPrefixed(prefix: String, arg: String): Unit =
- if (prefixes isDefinedAt prefix)
- prefixes(prefix) += arg
- else {
- prefixes(prefix) = new HashSet
- prefixes(prefix) += arg
- }
+ prefixes.getOrElseUpdate(prefix, new mutable.HashSet) += arg
def addBinding(tag: String, key: String, value: String): Unit =
- if (key.length() > 0) {
- if (bindings isDefinedAt tag)
- bindings(tag)(key) = value
- else {
- bindings(tag) = new HashMap
- bindings(tag)(key) = value
- }
- }
+ if (key.length > 0)
+ bindings.getOrElseUpdate(tag, new mutable.HashMap)(key) = value
- def addBinding(tag: String, binding: Pair[String, String]) {
+ def addBinding(tag: String, binding: Pair[String, String]): Unit =
addBinding(tag, binding._1, binding._2)
- }
def addOther(arg: String): Unit = others += arg
- def contains(option: String): Boolean = options contains option
+ def contains(option: String): Boolean = options(option)
def getArgument(option: String): Option[String] = arguments get option
- def getSuffixes(prefix: String): Set[String] =
- prefixes.get(prefix) match {
- case None => new HashSet
- case Some(set) => set
- }
+ def getSuffixes(prefix: String): mutable.Set[String] =
+ prefixes.getOrElse(prefix, new mutable.HashSet)
def containsSuffix(prefix: String, suffix: String): Boolean =
- prefixes.get(prefix) match {
- case None => false
- case Some(set) => set contains suffix
- }
+ prefixes get prefix exists (set => set(suffix))
- def getBindings(tag: String): Map[String, String] =
- bindings.get(tag) match {
- case None => new HashMap
- case Some(map) => map
- }
+ def getBindings(tag: String): mutable.Map[String, String] =
+ bindings.getOrElse(tag, new mutable.HashMap)
def getBinding(option: String, key: String): Option[String] =
- bindings.get(option) match {
- case None => None
- case Some(map) => map get key
- }
+ bindings get option flatMap (_ get key)
def getOthers: List[String] = others.toList
diff --git a/src/swing/scala/swing/Menu.scala b/src/swing/scala/swing/Menu.scala
index 21d1d7ae12..4419c71f8a 100644
--- a/src/swing/scala/swing/Menu.scala
+++ b/src/swing/scala/swing/Menu.scala
@@ -6,11 +6,9 @@
** |/ **
\* */
-
-
package scala.swing
-import scala.collection.mutable._
+import scala.collection.mutable
import javax.swing._
object MenuBar {
@@ -25,7 +23,7 @@ object MenuBar {
class MenuBar extends Component with SequentialContainer.Wrapper {
override lazy val peer: JMenuBar = new JMenuBar with SuperMixin
- def menus: Seq[Menu] = contents.filter(_.isInstanceOf[Menu]).map(_.asInstanceOf[Menu])
+ def menus: mutable.Seq[Menu] = contents.filter(_.isInstanceOf[Menu]).map(_.asInstanceOf[Menu])
// Not implemented by Swing
//def helpMenu: Menu = UIElement.cachedWrapper(peer.getHelpMenu)