summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2009-09-25 20:23:32 +0000
committerPaul Phillips <paulp@improving.org>2009-09-25 20:23:32 +0000
commit9f5eff8768d4ad41ea37d71a73835206736ff6bc (patch)
treece33a32e63c9eaa58042d4221b9f59dc4365f562 /src
parent15eb9333fa7fddc458f1c79da8ff1270ce990db2 (diff)
downloadscala-9f5eff8768d4ad41ea37d71a73835206736ff6bc.tar.gz
scala-9f5eff8768d4ad41ea37d71a73835206736ff6bc.tar.bz2
scala-9f5eff8768d4ad41ea37d71a73835206736ff6bc.zip
Short/Byte/Char/Int scrutinees will now be comp...
Short/Byte/Char/Int scrutinees will now be compiled into switches if all cases are literals. (There remain many things which can prevent switch creation.)
Diffstat (limited to 'src')
-rw-r--r--src/compiler/scala/tools/nsc/ast/TreeDSL.scala2
-rw-r--r--src/compiler/scala/tools/nsc/matching/ParallelMatching.scala4
-rw-r--r--src/compiler/scala/tools/nsc/matching/PatternNodes.scala2
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Unapplies.scala4
4 files changed, 7 insertions, 5 deletions
diff --git a/src/compiler/scala/tools/nsc/ast/TreeDSL.scala b/src/compiler/scala/tools/nsc/ast/TreeDSL.scala
index 3922e3fd40..1866fee719 100644
--- a/src/compiler/scala/tools/nsc/ast/TreeDSL.scala
+++ b/src/compiler/scala/tools/nsc/ast/TreeDSL.scala
@@ -43,7 +43,7 @@ trait TreeDSL {
if (f isDefinedAt x) Some(f(x)) else None
// Applies a function to a value and then returns the value.
- def applyAndReturn[T](f: T => Unit)(x: T): T = { f(x) ; x }
+ def returning[T](f: T => Unit)(x: T): T = { f(x) ; x }
// strip bindings to find what lies beneath
final def unbind(x: Tree): Tree = x match {
diff --git a/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala b/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala
index 941777c030..f0ef7b215b 100644
--- a/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala
+++ b/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala
@@ -170,7 +170,7 @@ trait ParallelMatching extends ast.TreeDSL {
}
}
- applyAndReturn[Tree](resetTraverser traverse _)(lxtt transform tree)
+ returning[Tree](resetTraverser traverse _)(lxtt transform tree)
}
final def isReached(bx: Int) = labels contains bx
@@ -366,7 +366,7 @@ trait ParallelMatching extends ast.TreeDSL {
// tests
def isDefined = sym ne NoSymbol
- def isSimple = tpe.isChar || tpe.isInt
+ def isSimple = tpe.isByte || tpe.isShort || tpe.isChar || tpe.isInt
// sequences
def seqType = tpe.widen baseType SeqClass
diff --git a/src/compiler/scala/tools/nsc/matching/PatternNodes.scala b/src/compiler/scala/tools/nsc/matching/PatternNodes.scala
index 45b63463e9..1278f417e5 100644
--- a/src/compiler/scala/tools/nsc/matching/PatternNodes.scala
+++ b/src/compiler/scala/tools/nsc/matching/PatternNodes.scala
@@ -93,6 +93,8 @@ trait PatternNodes extends ast.TreeDSL
// These tests for final classes can inspect the typeSymbol
private def is(s: Symbol) = tpe.typeSymbol eq s
+ def isByte = is(ByteClass)
+ def isShort = is(ShortClass)
def isInt = is(IntClass)
def isChar = is(CharClass)
def isBoolean = is(BooleanClass)
diff --git a/src/compiler/scala/tools/nsc/typechecker/Unapplies.scala b/src/compiler/scala/tools/nsc/typechecker/Unapplies.scala
index 7944e940ef..b586298560 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Unapplies.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Unapplies.scala
@@ -94,10 +94,10 @@ trait Unapplies extends ast.TreeDSL
}
def copyUntyped[T <: Tree](tree: T): T =
- applyAndReturn[T](UnTyper traverse _)(tree.duplicate)
+ returning[T](UnTyper traverse _)(tree.duplicate)
def copyUntypedInvariant(td: TypeDef): TypeDef =
- applyAndReturn[TypeDef](UnTyper traverse _)(
+ returning[TypeDef](UnTyper traverse _)(
treeCopy.TypeDef(td, td.mods &~ (COVARIANT | CONTRAVARIANT), td.name,
td.tparams, td.rhs).duplicate
)