summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBurak Emir <emir@epfl.ch>2006-11-27 17:45:58 +0000
committerBurak Emir <emir@epfl.ch>2006-11-27 17:45:58 +0000
commitc8a05b45e0a009a0b5062e5f91b593312ef76de6 (patch)
tree78e36a545fc6d99b5539c2f3107ed7f1ca4117ca /src
parent1e1dcc614bd5d70ff9f2e79dd7aafab57893f519 (diff)
downloadscala-c8a05b45e0a009a0b5062e5f91b593312ef76de6.tar.gz
scala-c8a05b45e0a009a0b5062e5f91b593312ef76de6.tar.bz2
scala-c8a05b45e0a009a0b5062e5f91b593312ef76de6.zip
fixed optimization trick in PM
Diffstat (limited to 'src')
-rw-r--r--src/compiler/scala/tools/nsc/matching/CodeFactory.scala4
-rw-r--r--src/compiler/scala/tools/nsc/matching/PatternMatchers.scala10
2 files changed, 10 insertions, 4 deletions
diff --git a/src/compiler/scala/tools/nsc/matching/CodeFactory.scala b/src/compiler/scala/tools/nsc/matching/CodeFactory.scala
index c3d373b731..56278738b4 100644
--- a/src/compiler/scala/tools/nsc/matching/CodeFactory.scala
+++ b/src/compiler/scala/tools/nsc/matching/CodeFactory.scala
@@ -219,5 +219,9 @@ trait CodeFactory requires transform.ExplicitOuter {
))))
}
+ def NotNull(tree:Tree) =
+ typed {
+ Apply(Select(tree, nme.ne), List(Literal(Constant(null))))
+ }
}
diff --git a/src/compiler/scala/tools/nsc/matching/PatternMatchers.scala b/src/compiler/scala/tools/nsc/matching/PatternMatchers.scala
index 56cedceb9e..8428423fd7 100644
--- a/src/compiler/scala/tools/nsc/matching/PatternMatchers.scala
+++ b/src/compiler/scala/tools/nsc/matching/PatternMatchers.scala
@@ -1178,12 +1178,14 @@ print()
}
val ntpe = node.getTpe
- var cond = typed { gen.mkIsInstanceOf(selector.duplicate, ntpe) }
+ var cond: Tree = null
// if type 2 test is same as static type, then just null test
- if(selector.tpe =:= ntpe) {
- cond = typed { Apply(Select(selector.duplicate, nme.ne), List(Literal(Constant(null)))) }
+ if(isSubType(selector.tpe,ntpe) && isSubType(ntpe, definitions.AnyRefClass.tpe)) {
+ cond = NotNull(selector.duplicate)
nstatic = nstatic + 1
+ } else {
+ cond = typed { gen.mkIsInstanceOf(selector.duplicate, ntpe) }
}
// compare outer instance for patterns like foo1.Bar foo2.Bar if not statically known to match
@@ -1220,7 +1222,7 @@ print()
if(!isSubType(selector.tpe, ntpe))
gen.mkIsInstanceOf(selector.duplicate, ntpe);
else
- Literal(Constant(true))
+ NotNull(selector.duplicate)
val treeAsSeq =
if(!isSubType(selector.tpe, ntpe))