in reply to optimization - exists should return a reference
There are two lines of though. One is that you're likely to need the value of the hash key after testing if it exists. The other is that, if you don't need it, but really just wanted to check if it exists, then you're loosing speed, not gaining it. Also, if all you really wanted was a bool, you just created and then destroyed a reference for nothing, which isn't exactly free.
The real solution would be common subexpression optimization, which is significantly more difficult.
You should benchmark exists (as it currently exists) vs. getting the value of a hash value, then consider usage patterns, and if it's worth it. Once you've got some numbers, talk to perl5-porters. Even better, once you've got some numbers and a patch...
You might also want to post to perl6-langauge about this -- since bool and ref context will be differencatable in perl6, you can get the best of both worlds. In fact, it could even return the value, but give "undef-but-true", etc, to give true results when the kv exists, but the value is false.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: optimization - exists should return a reference
by Elian (Parson) on Jan 15, 2003 at 23:03 UTC | |
|
Re: Re: optimization - exists should return a reference
by John M. Dlugosz (Monsignor) on Jan 16, 2003 at 03:50 UTC |