clear_defarray() is called during sub exit to clean up @_ in the
less common case where @_ has somehow gotten reified.
At the moment it just frees the old @_, then creates a new AV and
sticks it in pad[0].
This commit changes it so that for the reasonably common case of a reified
@_ where it's not magical and only has a reference count of 1, just call
av_clear() on it, rather than freeing and recreating.
Typical code that will benefit from this change is be something like:
sub f { push @_, ...; ... }
which causes the AV to be reified, but not to become otherwise visible.
PERL_ARGS_ASSERT_CLEAR_DEFARRAY;
- SvREFCNT_dec_NN(av);
- av = newAV();
- av_extend(av, fill);
+ if (LIKELY(!abandon && SvREFCNT(av) == 1 && !SvMAGICAL(av)))
+ av_clear(av);
+ else {
+ SvREFCNT_dec_NN(av);
+ av = newAV();
+ PAD_SVl(0) = MUTABLE_SV(av);
+ av_extend(av, fill);
+ }
AvREIFY_only(av);
- PAD_SVl(0) = MUTABLE_SV(av);
}