diff options
author | David Mitchell <davem@iabyn.com> | 2017-07-04 09:45:29 +0100 |
---|---|---|
committer | David Mitchell <davem@iabyn.com> | 2017-07-27 11:30:21 +0100 |
commit | 725c44f93c35f696d7175c36a6d2ec5987b5a4d1 (patch) | |
tree | 721f07a19addb4cffc53b5d7736dae71f68c01fb /hv.c | |
parent | b043c4bf3fff5c679dad74f1a0c13ac539a97815 (diff) | |
download | perl-725c44f93c35f696d7175c36a6d2ec5987b5a4d1.tar.gz |
use the new PL_sv_zero in obvious places
In places that do things like mPUSHi(0) or newSViv(0), replace them
with PUSHs(&PL_sv_zero) and &PL_sv_zero, etc.
This avoids the cost of creating and/or mortalising an SV, and/or setting
its value to 0.
This commit causes a subtle change to tainting in various places as a
side-effect. For example, grep in scalar context retunrs 0 if it has no
args. Formerly the zero value could in theory get tainted:
@a = ();
$x = ( ($^X . ""), grep { 1 } @a);
It used to be the case that $x would be tainted; now its not.
In practice this doesn't matter - the zero value was only getting tainted
as a side-effect of tainting's "if anything in the statement uses a
tainted value, taint everything" mechanism, which gives (documented) false
positives. This commit merely removes some such false positives, and
makes the behaviour similar to functions which return &PL_sv_undef/no/yes,
which are also immune to side-effect tainting.
Diffstat (limited to 'hv.c')
-rw-r--r-- | hv.c | 7 |
1 files changed, 4 insertions, 3 deletions
@@ -995,12 +995,13 @@ Perl_hv_bucket_ratio(pTHX_ HV *hv) return magic_scalarpack(hv, mg); } - sv = sv_newmortal(); - if (HvUSEDKEYS((HV *)hv)) + if (HvUSEDKEYS((HV *)hv)) { + sv = sv_newmortal(); Perl_sv_setpvf(aTHX_ sv, "%ld/%ld", (long)HvFILL(hv), (long)HvMAX(hv) + 1); + } else - sv_setiv(sv, 0); + sv = &PL_sv_zero; return sv; } |