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 false) So it's enough to check for trueness of $var before calling isa(). One less sub call.
Reply to This
Re: (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:
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)
Re: (Score:2)
Re: (Score:1)
Also anything else that needs custom isa values, asa.pm, Class::Adapter, Class::Decorator, and others.
The only legitimate use for the UNIVERSAL functions directly that I'm aware of is the UNIVERSAL::can($foo, 'can') which is a highly back-compatible method for testing "is $foo an object".
Re: (Score:2)
The only legitimate use for the UNIVERSAL functions directly that I'm aware of is the
UNIVERSAL::can($foo, 'can')which is a highly back-compatible method for testing "is $foo an object".So, maybe we could use this then:
or, as you seem to prefer:
No joke, I extended the original benchmarks with