Perl 5.x would take a speed hit in the general case, from your suggestion (instead of returning sv_yes, it would need to allocate a reference each time exists() was invoked).
Perl 6.x, on the other hand, would not, in the general case, take a speed hit, if boolean context were defined to evaluate to the existing behaviour, and non-boolean context, or more specifically, scalar context, would be the new (reference return value) behaviour.
Another consideration, is that the cost of a hash lookup may be equal, or less than, the cost of creating a reference, assigning the reference, and later dereferencing the reference.
I'm not sure if your suggestion is a good one. For Perl 6.x, I do not see a problem with it. Another argument for might be that the behaviour of exists would then become consistent with the behaviour of UNIVERSAL::can().
In reply to Re: optimization - exists should return a reference
by MarkM
in thread optimization - exists should return a reference
by John M. Dlugosz
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |