summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormihaylov <mihaylov@epfl.ch>2006-11-14 16:43:57 +0000
committermihaylov <mihaylov@epfl.ch>2006-11-14 16:43:57 +0000
commit25896b2d55b16cc6f0ccf4b890138db1ff0fe2e2 (patch)
tree86c730fd6f61758cf606fa0413c32e029df03db0
parentcc9e329bffd4cc2f6335140546adae15fe9ff9da (diff)
downloadscala-25896b2d55b16cc6f0ccf4b890138db1ff0fe2e2.tar.gz
scala-25896b2d55b16cc6f0ccf4b890138db1ff0fe2e2.tar.bz2
scala-25896b2d55b16cc6f0ccf4b890138db1ff0fe2e2.zip
Only shortcut nulls at the LHS of ==
-rw-r--r--src/compiler/scala/tools/nsc/backend/icode/GenICode.scala27
1 files changed, 12 insertions, 15 deletions
diff --git a/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala b/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala
index 298fdc7ee4..6269b012e6 100644
--- a/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala
+++ b/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala
@@ -1340,32 +1340,29 @@ abstract class GenICode extends SubComponent {
}
}
- val eqEqTemp: Name = "eqEqTemp$"
+ def eqEqTemp: Name = "eqEqTemp$"
/**
* Generate the "==" code for object references. It is equivalent of
* if (l eq null) then r eq null else l.equals(r);
*
- * @param l ...
- * @param r ...
- * @param ctx ...
+ * @param l left-hand side of the '=='
+ * @param r right-hand side of the '=='
+ * @param ctx current context
* @param thenCtx ...
* @param elseCtx ...
*/
def genEqEqPrimitive(l: Tree, r: Tree, ctx: Context,
thenCtx: Context, elseCtx: Context): Unit =
{
- // special-case reference (in)equality test for null
- val expr: Tree = Pair(l, r) match {
- case Pair(Literal(Constant(null)), expr) => expr
- case Pair(expr, Literal(Constant(null))) => expr
- case _ => null
- }
- if (expr ne null) {
- val ctx1 = genLoad(expr, ctx, ANY_REF_CLASS)
- ctx1.bb.emit(CZJUMP(thenCtx.bb, elseCtx.bb, EQ, ANY_REF_CLASS))
- ctx1.bb.close
- return
+ // special-case 'null == sth' to 'sth eq null'
+ l match {
+ case Literal(Constant(null)) =>
+ val ctx1 = genLoad(r, ctx, ANY_REF_CLASS)
+ ctx1.bb.emit(CZJUMP(thenCtx.bb, elseCtx.bb, EQ, ANY_REF_CLASS))
+ ctx1.bb.close
+ return
+ case _ => ()
}
var eqEqTempVar: Symbol = null