diff options
author | Burak Emir <emir@epfl.ch> | 2006-11-27 17:45:58 +0000 |
---|---|---|
committer | Burak Emir <emir@epfl.ch> | 2006-11-27 17:45:58 +0000 |
commit | c8a05b45e0a009a0b5062e5f91b593312ef76de6 (patch) | |
tree | 78e36a545fc6d99b5539c2f3107ed7f1ca4117ca | |
parent | 1e1dcc614bd5d70ff9f2e79dd7aafab57893f519 (diff) | |
download | scala-c8a05b45e0a009a0b5062e5f91b593312ef76de6.tar.gz scala-c8a05b45e0a009a0b5062e5f91b593312ef76de6.tar.bz2 scala-c8a05b45e0a009a0b5062e5f91b593312ef76de6.zip |
fixed optimization trick in PM
-rw-r--r-- | src/compiler/scala/tools/nsc/matching/CodeFactory.scala | 4 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/matching/PatternMatchers.scala | 10 |
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)) |