diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2013-09-17 16:03:25 +0200 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2013-09-18 17:00:35 +0200 |
commit | 354f4280f3bfbf033aa28100b4c74bc9b923dcbd (patch) | |
tree | 5f85793059f8483c9765755b0e3c374ab9b69aba /src/compiler | |
parent | 4faaa82910940ffd5eaf0b853ec041176ec7fd0d (diff) | |
download | scala-354f4280f3bfbf033aa28100b4c74bc9b923dcbd.tar.gz scala-354f4280f3bfbf033aa28100b4c74bc9b923dcbd.tar.bz2 scala-354f4280f3bfbf033aa28100b4c74bc9b923dcbd.zip |
SI-7852 Omit null check for SomeModule.==
For the same reasons outlined in the previous commits.
Diffstat (limited to 'src/compiler')
-rw-r--r-- | src/compiler/scala/tools/nsc/backend/icode/GenICode.scala | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala b/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala index 1413add240..a80fee876e 100644 --- a/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala +++ b/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala @@ -1320,6 +1320,7 @@ abstract class GenICode extends SubComponent { */ def isNull(t: Tree) = cond(t) { case Literal(Constant(null)) => true } def isLiteral(t: Tree) = cond(t) { case Literal(_) => true } + def isNonNullExpr(t: Tree) = isLiteral(t) || ((t.symbol ne null) && t.symbol.isModule) /* If l or r is constant null, returns the other ; otherwise null */ def ifOneIsNull(l: Tree, r: Tree) = if (isNull(l)) r else if (isNull(r)) l else null @@ -1515,8 +1516,12 @@ abstract class GenICode extends SubComponent { val branchesReachable = !ctx1.bb.ignore ctx1.bb emitOnly CZJUMP(thenCtx.bb, elseCtx.bb, EQ, ObjectReference) branchesReachable - } else if (isLiteral(l)) { - // "" == expr -> "".equals(expr) (no null check) + } else if (isNonNullExpr(l)) { + // Avoid null check if L is statically non-null. + // + // "" == expr -> "".equals(expr) + // Nil == expr -> Nil.equals(expr) + // // Common enough (through pattern matching) to treat this specially here rather than // hoping that -Yconst-opt is enabled. The impossible branches for null checks lead // to spurious "branch not covered" warnings in Jacoco code coverage. |