diff options
author | Gilles Dubochet <gilles.dubochet@epfl.ch> | 2007-05-20 16:05:38 +0000 |
---|---|---|
committer | Gilles Dubochet <gilles.dubochet@epfl.ch> | 2007-05-20 16:05:38 +0000 |
commit | a43e6b1242018f538a25efd70e74ab87abc8691d (patch) | |
tree | 1e374930c79cfc2d2738609b09c7dd8b41bec971 /src/compiler | |
parent | d8e55969506c6db2ac21948128404ddf938d4b8c (diff) | |
download | scala-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/compiler')
-rw-r--r-- | src/compiler/scala/tools/nsc/backend/icode/GenICode.scala | 15 |
1 files changed, 11 insertions, 4 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) { |