diff options
author | schinz <schinz@epfl.ch> | 2005-03-27 09:55:28 +0000 |
---|---|---|
committer | schinz <schinz@epfl.ch> | 2005-03-27 09:55:28 +0000 |
commit | 9602bf11e93ac5a449f0ab492f3c74f2fa45fa56 (patch) | |
tree | 7a14cc6a3ff3110b3fca75f1da33b4627562d2a1 /sources | |
parent | a274f949c3aa9db16bd5addd0eed4f85388e74ed (diff) | |
download | scala-9602bf11e93ac5a449f0ab492f3c74f2fa45fa56.tar.gz scala-9602bf11e93ac5a449f0ab492f3c74f2fa45fa56.tar.bz2 scala-9602bf11e93ac5a449f0ab492f3c74f2fa45fa56.zip |
- changed pattern matcher to use the erased ver...
- changed pattern matcher to use the erased versions of asInstanceOf
when possible, to gain some speed when run time types are enabled; i.e.
instead of generating code like this:
if (x.isInstanceOf[List[Int]]) {
val temp$ = x.asInstanceOf[List[Int]];
...
}
the pattern matcher now generates code like that:
if (x.isInstanceOf[List[Int]]) {
val temp$ = x.asInstanceOf$erased[List[Int]];
...
}
Diffstat (limited to 'sources')
-rw-r--r-- | sources/scala/tools/scalac/transformer/matching/PatternMatcher.scala | 6 | ||||
-rw-r--r-- | sources/scalac/ast/TreeGen.java | 22 |
2 files changed, 17 insertions, 11 deletions
diff --git a/sources/scala/tools/scalac/transformer/matching/PatternMatcher.scala b/sources/scala/tools/scalac/transformer/matching/PatternMatcher.scala index f731648124..7249cc4360 100644 --- a/sources/scala/tools/scalac/transformer/matching/PatternMatcher.scala +++ b/sources/scala/tools/scalac/transformer/matching/PatternMatcher.scala @@ -897,7 +897,7 @@ class PatternMatcher(unit: CompilationUnit) extends PatternTool(unit) { case ConstrPat(casted) => return gen.If(gen.mkIsInstanceOf(selector.duplicate(), node.getTpe()), gen.mkBlock(gen.ValDef(casted, - gen.mkAsInstanceOf(selector.duplicate(), node.getTpe())), + gen.mkAsInstanceOf(selector.pos, selector.duplicate(), node.getTpe(), true)), toTree(node.and)), toTree(node.or, selector.duplicate())); case SequencePat(casted, len) => @@ -905,11 +905,11 @@ class PatternMatcher(unit: CompilationUnit) extends PatternTool(unit) { cf.Or( cf.And( cf.And(gen.mkIsInstanceOf(selector.duplicate(), node.getTpe()), - cf.Equals(gen.mkApply__(gen.Select(gen.mkAsInstanceOf(selector.duplicate(), node.getTpe()), + cf.Equals(gen.mkApply__(gen.Select(gen.mkAsInstanceOf(selector.pos, selector.duplicate(), node.getTpe(), true), defs.SEQ_LENGTH())), gen.mkIntLit(selector.pos, len))), gen.mkBlock(gen.ValDef(casted, - gen.mkAsInstanceOf(selector.duplicate(), node.getTpe())), + gen.mkAsInstanceOf(selector.pos, selector.duplicate(), node.getTpe(), true)), toTree(node.and))), toTree(node.or, selector.duplicate())); case ConstantPat(value) => diff --git a/sources/scalac/ast/TreeGen.java b/sources/scalac/ast/TreeGen.java index 43d1fc1ed5..9167a4cf94 100644 --- a/sources/scalac/ast/TreeGen.java +++ b/sources/scalac/ast/TreeGen.java @@ -640,23 +640,29 @@ public class TreeGen implements Kinds, Modifiers, TypeTags { } /** Builds an instance test with given value and type. */ - public Tree mkIsInstanceOf(int pos, Tree value, Type type) { - Symbol sym = global.currentPhase.id >= global.PHASE.TYPESASVALUES.id() - ? definitions.ANY_IS_ERASED - : definitions.ANY_IS; + public Tree mkIsInstanceOf(int pos, Tree value, Type type, boolean erased) { + Symbol sym = erased ? definitions.ANY_IS_ERASED : definitions.ANY_IS; return mkApplyT_(pos, Select(value, sym), new Type[]{type}); } + public Tree mkIsInstanceOf(int pos, Tree value, Type type) { + boolean afterTAV = + global.currentPhase.id >= global.PHASE.TYPESASVALUES.id(); + return mkIsInstanceOf(pos, value, type, afterTAV); + } public Tree mkIsInstanceOf(Tree value, Type type) { return mkIsInstanceOf(value.pos, value, type); } /** Builds a cast with given value and type. */ - public Tree mkAsInstanceOf(int pos, Tree value, Type type) { - Symbol sym = global.currentPhase.id >= global.PHASE.TYPESASVALUES.id() - ? definitions.ANY_AS_ERASED - : definitions.ANY_AS; + public Tree mkAsInstanceOf(int pos, Tree value, Type type, boolean erased) { + Symbol sym = erased ? definitions.ANY_AS_ERASED : definitions.ANY_AS; return mkApplyT_(pos, Select(value, sym), new Type[]{type}); } + public Tree mkAsInstanceOf(int pos, Tree value, Type type) { + boolean afterTAV = + global.currentPhase.id >= global.PHASE.TYPESASVALUES.id(); + return mkAsInstanceOf(pos, value, type, afterTAV); + } public Tree mkAsInstanceOf(Tree value, Type type) { return mkAsInstanceOf(value.pos, value, type); } |