On 1/3/15 8:43 PM, Jonathan Marler wrote:
On Sunday, 4 January 2015 at 03:14:31 UTC, Andrei Alexandrescu wrote:
On 1/3/15 5:30 PM, Jonathan Marler wrote:
I've recently looked at how the '==' operator works with classes.  I was
disappointed to find that 'a == b' always gets rewritten to:

.object.opEquals(a, b);

The reason for my disappointment is that this results in unnecessary
overhead. I would think that the compiler would first try to rewrite the
'==' operator using a type-specific opEquals method, then fall back on
the generic version if one did not exist.  Is there a reason for this?

TDPL has a detailed explanation of that, including a reference to
Java's approach. There's less overhead in calling the free function in
object (it's inlinable and if e.g. the references are equal there's no
virtual call overhead).

Andrei

Can you point me to that detailed explanation?

You'd need to buy TDPL. In turn, TDPL refers this article: http://www.drdobbs.com/jvm/java-qa-how-do-i-correctly-implement-th/184405053 -- Andrei

Reply via email to