NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.
All the Perl that's Practical to Extract and Report
Stories, comments, journals, and other submissions on use Perl; are Copyright 1998-2006, their respective owners.
Find the invariant (Score:1)
So try to find (or establish) the boundary where $var is always known to not be undef. Test it once there, and not in an inner loop. If possible, it may very well not be.
If that's not feasible, how about introducing null objects instead of undef values?
Re: squeezing out performance. Do you need the overhead of calling blessed? If $var contains a string instead of an object, $var->isa is going to work as a class method anyway, right? (and return fa
Re:Find the invariant (Score:2)
At the present time, the possible values of $var are strings, arrayrefs, hashrefs and regular expressions. That's why the blessed call is in there. However, there is one naughty trick I can do. The class I'm actually testing for creates logic variables. Since I control that class, if I declare that class as final and since I don't override isa, I can use UNIVERSAL::isa() as a function call:
That's a huge performance gain and in this limited case, it's safe.
Reply to This
Parent
Re: (Score:1)
If you were really evil, you could avoid the sub call, stringify the possibly-a-ref, and check the first n characters against the name of your class.
Re: (Score:2)