diff options
author | Daniel Dragan <bulk88@hotmail.com> | 2012-11-10 12:49:38 -0500 |
---|---|---|
committer | Father Chrysostomos <sprout@cpan.org> | 2012-11-12 08:35:32 -0800 |
commit | fa3febb6e5b7a5e436c9b0a4104a1bc22803bc49 (patch) | |
tree | b4bf9c7e397dce188d7a4222b698586c93afc9a5 /universal.c | |
parent | 4cbe3a7d4e9196aab2ca064651827e69cfa50f74 (diff) | |
download | perl-fa3febb6e5b7a5e436c9b0a4104a1bc22803bc49.tar.gz |
add items checking to Internals::SvREFCNT
Add item count checking to Internals::SvREFCNT in case prototype is
bypassed. Getting rid of the undef saves some instructions. Reading
SvREFCNT(sv) only once save an instruction.
Diffstat (limited to 'universal.c')
-rw-r--r-- | universal.c | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/universal.c b/universal.c index 8cc6e63a93..be06acac7a 100644 --- a/universal.c +++ b/universal.c @@ -922,29 +922,29 @@ XS(XS_Internals_SvREADONLY) /* This is dangerous stuff. */ } XSRETURN_UNDEF; /* Can't happen. */ } - XS(XS_Internals_SvREFCNT) /* This is dangerous stuff. */ { dVAR; dXSARGS; SV * const svz = ST(0); SV * sv; + U32 refcnt; PERL_UNUSED_ARG(cv); /* [perl #77776] - called as &foo() not foo() */ - if (!SvROK(svz)) + if ((items != 1 && items != 2) || !SvROK(svz)) croak_xs_usage(cv, "SCALAR[, REFCOUNT]"); sv = SvRV(svz); - if (items == 1) - XSRETURN_UV(SvREFCNT(sv) - 1); /* Minus the ref created for us. */ - else if (items == 2) { /* I hope you really know what you are doing. */ - SvREFCNT(sv) = SvUV(ST(1)) + 1; /* we free one ref on exit */ - XSRETURN_UV(SvREFCNT(sv) - 1); - } - XSRETURN_UNDEF; /* Can't happen. */ + /* idea is for SvREFCNT(sv) to be accessed only once */ + refcnt = items == 2 ? + /* we free one ref on exit */ + (SvREFCNT(sv) = SvUV(ST(1)) + 1) + : SvREFCNT(sv); + XSRETURN_UV(refcnt - 1); /* Minus the ref created for us. */ + } XS(XS_Internals_hv_clear_placehold) |