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: (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
Params::Util and UNIVERSAL::can (Score:1)
Params::Util::_INSTANCE has long done Scalar::Util::blessed($foo) and $foo->isa('bar'), I'd be interested to see how much overhead the extra function call adds.
Also, try substituting UNIVERSAL::can($foo, 'can') for blessed($foo)
Re: (Score:1)
Re: (Score:2)
So you want a fully qualified call to blessed instead of my importing it? Or did you miss that I had called blessed? UNIVERSAL::can('isa') is interestesting, but I'm sure that won't be much faster. I've added both of those (the fully qualified Scalar::Util::blessed() is called 'fqblessed', of course).
Re: (Score:1)