diff options
author | Paul Phillips <paulp@improving.org> | 2010-06-21 04:59:52 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2010-06-21 04:59:52 +0000 |
commit | c65032c3f629ebebd7928f5d59988533f80b0c65 (patch) | |
tree | 3d849f87a5391a591ce3cc1a6fe29864033236c3 /src/library | |
parent | b040ad441b8a9d89c9ea6d890381ed61d0285f25 (diff) | |
download | scala-c65032c3f629ebebd7928f5d59988533f80b0c65.tar.gz scala-c65032c3f629ebebd7928f5d59988533f80b0c65.tar.bz2 scala-c65032c3f629ebebd7928f5d59988533f80b0c65.zip |
Added some null checks to == logic.
sense that there are a few code paths where null may be checked
redundantly, but I deemed further optimization too risky. Review by
odersky.
Diffstat (limited to 'src/library')
-rw-r--r-- | src/library/scala/runtime/BoxesRunTime.java | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/src/library/scala/runtime/BoxesRunTime.java b/src/library/scala/runtime/BoxesRunTime.java index 8bce46ea66..b6539d087c 100644 --- a/src/library/scala/runtime/BoxesRunTime.java +++ b/src/library/scala/runtime/BoxesRunTime.java @@ -127,7 +127,6 @@ public final class BoxesRunTime public static boolean equals(Object x, Object y) { if (x == y) return true; - if (x == null) return false; return equals2(x, y); } @@ -139,6 +138,8 @@ public final class BoxesRunTime return equalsNumObject((java.lang.Number)x, y); if (x instanceof java.lang.Character) return equalsCharObject((java.lang.Character)x, y); + if (x == null) + return y == null; return x.equals(y); } @@ -146,8 +147,10 @@ public final class BoxesRunTime public static boolean equalsNumObject(java.lang.Number xn, Object y) { if (y instanceof java.lang.Number) return equalsNumNum(xn, (java.lang.Number)y); - else if (y instanceof java.lang.Character) + if (y instanceof java.lang.Character) return equalsNumChar(xn, (java.lang.Character)y); + if (xn == null) + return y == null; return xn.equals(y); } @@ -168,6 +171,9 @@ public final class BoxesRunTime if ((yn instanceof ScalaNumber) && !(xn instanceof ScalaNumber)) return yn.equals(xn); } + if (xn == null) + return yn == null; + return xn.equals(yn); } @@ -176,6 +182,8 @@ public final class BoxesRunTime return xc.charValue() == ((java.lang.Character)y).charValue(); if (y instanceof java.lang.Number) return equalsNumChar((java.lang.Number)y, xc); + if (xc == null) + return y == null; return xc.equals(y); } @@ -192,6 +200,9 @@ public final class BoxesRunTime case DOUBLE: return xn.doubleValue() == ch; default: + if (xn == null) + return yc == null; + return xn.equals(yc); } } |