I try to speed up Params::Util using XS. One method the author wrote, allows a method to override the isa() method, so sv_derived_from() doesn't work in any case.
I used following code now:
void
_INSTANCE(ref,type)
SV *ref;
char *type;
PROTOTYPE: $$
CODE:
{
STRLEN len;
if( SvROK(ref) && type && ( ( len = strlen(type) ) > 0 ) )
{
if( SvMAGICAL(ref) )
mg_get(ref);
if( sv_isobject(ref) )
{
if( sv_derived_from(ref,type) )
{
ST(0) = ref;
XSRETURN(1);
}
else
{
I32 isa_type = 0;
int count;
ENTER;
SAVETMPS;
PUSHMARK(SP);
XPUSHs( sv_2mortal( newSVsv( ref ) ) );
XPUSHs( sv_2mortal( newSVpv( type, len ) ) );
PUTBACK;
if( ( count = call_method("isa", G_SCALAR) ) )
{
I32 oldax = ax;
SPAGAIN;
SP -= count;
ax = (SP - PL_stack_base) + 1;
isa_type = SvIV(ST(0));
ax = oldax;
}
PUTBACK;
FREETMPS;
LEAVE;
if( isa_type )
{
ST(0) = ref;
XSRETURN(1);
}
}
}
}
XSRETURN_UNDEF;
}
Why is it necessary to save ax and why isn't it documented in perlcall (http://search.cpan.org/~rgarcia/perl-5.10.0/pod/perlcall.pod#Using_Perl_to_dispose_of_temporaries)?
Did I understand sth. wrong and made another mistake?
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.