On Thursday, 6 June 2013 at 18:27:10 UTC, Walter Bright wrote:
On 6/6/2013 11:11 AM, deadalnix wrote:
It is also possible to automatically generate code like :
if (virtualMethod == givenMethod) {
givenMethod();
} else {
virtualMethod();
}
It sound like it is completely stupid, but in fact, as the
compiler know the
call you'll do, it can run optimizations.
You're right, that is a valid optimization for virtual methods.
But, it is not as good as final, because the call to
virtualMethod() negatively affects the code generation even if
it is never called.
(This is because of things like function calls destroy the
scratch registers, meaning that variables can't easily be
enregistered into them.)
Yes, which happen anyway for shared objects !