diff options
author | David Mitchell <davem@iabyn.com> | 2015-08-28 08:21:05 +0100 |
---|---|---|
committer | David Mitchell <davem@iabyn.com> | 2016-02-03 08:59:39 +0000 |
commit | a62db3cf33709cf64db55ca8a466c34d151b8392 (patch) | |
tree | 4da471bc773d9c12814d9a8bcc506b91bfe87f0c /t | |
parent | 9af0df0b57d248c9c26f1464e1f1c18f24c642c2 (diff) | |
download | perl-a62db3cf33709cf64db55ca8a466c34d151b8392.tar.gz |
pp_enteriter: don't create new SV for GvSV slot
Currently in
for $pkg_var (...) {}
pp_enteriter() saves the current SV that's in the GvSV slot, then
replaces it with a newSV(0). Instead, leave it untouched. In the range
cases:
for $pkg_var (1..10) {}
for $pkg_var ('a'..'z') {}
a new SV will be created anyway in the first call to pp_iter(), since each
time round the loop it checks whether the refcount of the iterator vars is
greater than 1 and if so abandons it.
For the list case, e.g.
for $pkg_var (1,3,5) {}
for $pkg_var (@foo) {}
each call to pp_iter updates the GvSV slot to point to the current var,
so sticking a null SV in there initially, and freeing it the end is just
pointless extra work.
The only slight proviso is when the GvSV slot is initially NULL. In this
rare case we still create the SV, as it will be needed for the range
cases.
Diffstat (limited to 't')
-rw-r--r-- | t/op/for.t | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/t/op/for.t b/t/op/for.t index 65a746497a..ef60f4d622 100644 --- a/t/op/for.t +++ b/t/op/for.t @@ -5,7 +5,7 @@ BEGIN { require "./test.pl"; } -plan(111); +plan(112); # A lot of tests to check that reversed for works. @@ -620,3 +620,14 @@ is(fscope(), 1, 'return via loop in sub'); ok(!defined $foo, "NULL GvSV"); } } + +# make sure storing an int in a NULL GvSV is ok + +{ + local $foo = "boo"; + { + local *foo; + for $foo (1..2) {} + ok(!defined $foo, "NULL GvSV int iterator"); + } +} |