On Wed, Oct 10, 2012 at 6:15 AM, martin odersky <
martin....@epfl.ch> wrote:
> Question 1: It looks like the prelude to the equals call contains two null
> pointer checks. The first is redundant because we test an object, which
> should be always non-null (right?) The second is also redundant because
> equals should handle the case of a null argument anyway (right?). Can we get
> rid of the tests?
I think you're misreading it. The logic being applied is:
if (l eq null) r eq null else l.equals(r);
We can't lose the null check on the left because:
var x: Nil.type = null
x match { ...
And the null check on the right is only performed if the left hand side is null.
> Question 2: It seems attractive in the interest of performance to change
> the spec of pattern matching for case objects: these could use an instanceof
> check instead of an equals operation. That would speed up tests against Nil
> considerably. On the other hand, a Vector() would not longer be matched by a
> Nil. But is that even desirable?
I'm not sure it's desirable for Vector() to match Nil either, but it
would be such a dangerously breaking change, we'd be looking at the
far future. Any change which affects pattern matcher semantics is
deadly because there will be no indication in the affected code - it
will just stop/start matching.