summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGilles Dubochet <gilles.dubochet@epfl.ch>2007-05-20 16:05:38 +0000
committerGilles Dubochet <gilles.dubochet@epfl.ch>2007-05-20 16:05:38 +0000
commita43e6b1242018f538a25efd70e74ab87abc8691d (patch)
tree1e374930c79cfc2d2738609b09c7dd8b41bec971 /src
parentd8e55969506c6db2ac21948128404ddf938d4b8c (diff)
downloadscala-a43e6b1242018f538a25efd70e74ab87abc8691d.tar.gz
scala-a43e6b1242018f538a25efd70e74ab87abc8691d.tar.bz2
scala-a43e6b1242018f538a25efd70e74ab87abc8691d.zip
Rich comparison (scala.runtime.Comparator.equal...
Rich comparison (scala.runtime.Comparator.equals) is not inserted when both sides of an equality are statically known to be equal and of a subtype of Number or Character. This is an optimisation — behaviour should be equivalent as their own equal methods should do ok.
Diffstat (limited to 'src')
-rw-r--r--src/compiler/scala/tools/nsc/backend/icode/GenICode.scala15
-rw-r--r--src/library/scala/runtime/Comparator.java4
2 files changed, 13 insertions, 6 deletions
diff --git a/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala b/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala
index b668e28c05..5ddf6b052d 100644
--- a/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala
+++ b/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala
@@ -1378,15 +1378,22 @@ abstract class GenICode extends SubComponent {
local
}
+ /** True if the equality comparison is between values that require the use of the rich equality
+ * comparator (scala.runtime.Comparator.equals). This is the case when either side of the
+ * comparison might have a run-time type subtype of java.lang.Number or java.lang.Character.
+ * When it is statically known that both sides are equal and subtypes of Number of Character,
+ * not using the rich equality is possible (their own equals method will do ok.)*/
def mustUseAnyComparator: Boolean = {
val lsym = l.tpe.symbol
val rsym = r.tpe.symbol
(lsym == definitions.ObjectClass) ||
(rsym == definitions.ObjectClass) ||
- (lsym isNonBottomSubClass definitions.BoxedNumberClass)||
- (!forMSIL && (lsym isNonBottomSubClass BoxedCharacterClass)) ||
- (rsym isNonBottomSubClass definitions.BoxedNumberClass) ||
- (!forMSIL && (rsym isNonBottomSubClass BoxedCharacterClass))
+ (lsym != rsym) && (
+ (lsym isNonBottomSubClass definitions.BoxedNumberClass) ||
+ (!forMSIL && (lsym isNonBottomSubClass BoxedCharacterClass)) ||
+ (rsym isNonBottomSubClass definitions.BoxedNumberClass) ||
+ (!forMSIL && (rsym isNonBottomSubClass BoxedCharacterClass))
+ )
}
if (mustUseAnyComparator) {
diff --git a/src/library/scala/runtime/Comparator.java b/src/library/scala/runtime/Comparator.java
index c73c7506ba..705bf30d5c 100644
--- a/src/library/scala/runtime/Comparator.java
+++ b/src/library/scala/runtime/Comparator.java
@@ -36,8 +36,8 @@ public class Comparator {
* ICode phase, method <code>genEqEqPrimitive</code>) only when either
* side of the comparison is a subclass of <code>AnyVal</code>, of
* <code>java.lang.Number</code>, of <code>java.lang.Character</code> or
- * is exactly <code>Any</code> or <code>AnyRef</code>.
- */
+ * is exactly <code>Any</code> or <code>AnyRef</code>, but when both sides
+ * have different types. */
public static boolean equals(Object a, Object b) {
if (a == null)
return b == null;