diff options
author | Paul Phillips <paulp@improving.org> | 2012-02-20 20:50:18 -0800 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2012-02-20 21:59:06 -0800 |
commit | fbb7865e137e83660257fdc79d19d29ff39c775b (patch) | |
tree | e4d18fe487522572aee44701b78fcd8f6afdc5b4 /src/compiler | |
parent | 7a5966f9fa6f47e18b8dab080e7f629625ed093e (diff) | |
download | scala-fbb7865e137e83660257fdc79d19d29ff39c775b.tar.gz scala-fbb7865e137e83660257fdc79d19d29ff39c775b.tar.bz2 scala-fbb7865e137e83660257fdc79d19d29ff39c775b.zip |
Eliminating duplication in zero creation.
Diffstat (limited to 'src/compiler')
-rw-r--r-- | src/compiler/scala/reflect/internal/TreeGen.scala | 27 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/backend/icode/GenICode.scala | 26 |
2 files changed, 24 insertions, 29 deletions
diff --git a/src/compiler/scala/reflect/internal/TreeGen.scala b/src/compiler/scala/reflect/internal/TreeGen.scala index e537c6b83f..cc882ad5ed 100644 --- a/src/compiler/scala/reflect/internal/TreeGen.scala +++ b/src/compiler/scala/reflect/internal/TreeGen.scala @@ -250,20 +250,19 @@ abstract class TreeGen { * var x: T = _ * which is appropriate to the given Type. */ - def mkZero(tp: Type): Tree = { - val tree = tp.typeSymbol match { - case UnitClass => Literal(Constant()) - case BooleanClass => Literal(Constant(false)) - case FloatClass => Literal(Constant(0.0f)) - case DoubleClass => Literal(Constant(0.0d)) - case ByteClass => Literal(Constant(0.toByte)) - case ShortClass => Literal(Constant(0.toShort)) - case IntClass => Literal(Constant(0)) - case LongClass => Literal(Constant(0L)) - case CharClass => Literal(Constant(0.toChar)) - case _ => Literal(Constant(null)) - } - tree setType tp + def mkZero(tp: Type): Tree = Literal(mkConstantZero(tp)) setType tp + + def mkConstantZero(tp: Type): Constant = tp.typeSymbol match { + case UnitClass => Constant(()) + case BooleanClass => Constant(false) + case FloatClass => Constant(0.0f) + case DoubleClass => Constant(0.0d) + case ByteClass => Constant(0.toByte) + case ShortClass => Constant(0.toShort) + case IntClass => Constant(0) + case LongClass => Constant(0L) + case CharClass => Constant(0.toChar) + case _ => Constant(null) } def mkZeroContravariantAfterTyper(tp: Type): Tree = { diff --git a/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala b/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala index e1731c5259..dd65e825c3 100644 --- a/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala +++ b/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala @@ -879,23 +879,19 @@ abstract class GenICode extends SubComponent { } else if (sym.elisionLevel.exists (_ < settings.elidebelow.value || settings.noassertions.value)) { // XXX settings.noassertions.value temporarily retained to avoid // breakage until a reasonable interface is settled upon. - debuglog("Eliding call from " + tree.symbol.owner + " to " + sym + " based on its elision threshold of " + sym.elisionLevel.get) - val value = expectedType match { - case UNIT => () - case BOOL => false - case BYTE => 0:Byte - case SHORT => 0:Short - case CHAR => '?' - case INT => 0 - case LONG => 0L - case FLOAT => 0.0f - case DOUBLE => 0.0 - case _ => null + debuglog("Eliding call from " + tree.symbol.owner + " to " + sym + + " based on its elision threshold of " + sym.elisionLevel.get) + if (expectedType.isValueType) { + ctx.bb.emit(CONSTANT(global.gen.mkConstantZero(expectedType.toType)), tree.pos) + generatedType = expectedType + } + else { + ctx.bb.emit(CONSTANT(Constant(null)), tree.pos) + generatedType = NullReference } - ctx.bb.emit(CONSTANT(Constant(value)), tree.pos) - generatedType = if (expectedType.isInstanceOf[ValueTypeKind]) expectedType else NullReference ctx - } else { // normal method call + } + else { // normal method call debuglog("Gen CALL_METHOD with sym: " + sym + " isStaticSymbol: " + sym.isStaticMember); val invokeStyle = if (sym.isStaticMember) |