diff options
author | Daniel Dragan <bulk88@hotmail.com> | 2014-10-10 13:29:33 -0400 |
---|---|---|
committer | Father Chrysostomos <sprout@cpan.org> | 2014-10-10 14:30:21 -0700 |
commit | a953aca586d48d6f0b2c4db3572de328ed6d85e8 (patch) | |
tree | 244c1608b1f36a40c1c0b27105586d1d19949f65 /sv.c | |
parent | de183bbb2f50be045697c1759931907c5e7bdf28 (diff) | |
download | perl-a953aca586d48d6f0b2c4db3572de328ed6d85e8.tar.gz |
optimize & rmv from public API Perl_tmps_grow and related code
Previously in PUSH_EXTEND_MORTAL__SV_C, "PL_tmps_ix + 1" would execute
twice, once for the nonmutable if(>=), then again after the potential
tmps_grow call. tmps_grow has an unused return register/void proto, put it
to use by returning ix. Also change tmps_grow to take the result of
"PL_tmps_ix + the constant (usually 1) or non-constant (EXTEND_MORTAL)".
This avoid having to put the constant twice in machine code, once for the
if test, 2nd time for extend length param for tmps_grow call. For
non-constant/EXTEND_MORTAL usage, it allows the C optimizer to have the
length var to go out of liveness sooner if possible. Also the var used for
the if(>=) test is more likely to be in a register than length var.
So "if test variable" is closer on hand to the CPU than length var. In some
cases, if non-const len var isn't used again, it becomes the "ix" variable
by having PL_tmps_ix added to it. Change sv_2mortal to return sv instead
of NULL to remove a unique branch/block of machine code that assigns 0 to
return variable (Visual C didn't figure out return sv == returned NULL,
not sv). See also [perl #121845].
Diffstat (limited to 'sv.c')
-rw-r--r-- | sv.c | 8 |
1 files changed, 5 insertions, 3 deletions
@@ -8906,8 +8906,10 @@ Perl_sv_dec_nomg(pTHX_ SV *const sv) */ #define PUSH_EXTEND_MORTAL__SV_C(AnSv) \ STMT_START { \ - EXTEND_MORTAL(1); \ - PL_tmps_stack[++PL_tmps_ix] = (AnSv); \ + SSize_t ix = ++PL_tmps_ix; \ + if (UNLIKELY(ix >= PL_tmps_max)) \ + ix = tmps_grow_p(ix); \ + PL_tmps_stack[ix] = (AnSv); \ } STMT_END /* @@ -9029,7 +9031,7 @@ Perl_sv_2mortal(pTHX_ SV *const sv) { dVAR; if (!sv) - return NULL; + return sv; if (SvIMMORTAL(sv)) return sv; PUSH_EXTEND_MORTAL__SV_C(sv); |