diff options
author | Richard Leach <richardleach@users.noreply.github.com> | 2021-04-19 21:28:01 +0100 |
---|---|---|
committer | Hugo van der Sanden <hv@crypt.org> | 2021-05-26 13:42:43 +0100 |
commit | d2a9e960038ce8485fc1eb7b94297c9e5b0a4033 (patch) | |
tree | 0032b2e59ac1fc6d36036eca4de9ca96d8cd2bd0 /pp_hot.c | |
parent | 0b1c19ab1cbed9c221a41fca38580344778ce3a6 (diff) | |
download | perl-d2a9e960038ce8485fc1eb7b94297c9e5b0a4033.tar.gz |
Perl_clear_defarray: faster array creation via new macro+function
Diffstat (limited to 'pp_hot.c')
-rw-r--r-- | pp_hot.c | 7 |
1 files changed, 3 insertions, 4 deletions
@@ -4966,8 +4966,6 @@ PP(pp_leavesub) void Perl_clear_defarray(pTHX_ AV* av, bool abandon) { - const SSize_t fill = AvFILLp(av); - PERL_ARGS_ASSERT_CLEAR_DEFARRAY; if (LIKELY(!abandon && SvREFCNT(av) == 1 && !SvMAGICAL(av))) { @@ -4975,8 +4973,9 @@ Perl_clear_defarray(pTHX_ AV* av, bool abandon) AvREIFY_only(av); } else { - AV *newav = newAV(); - av_extend(newav, fill); + const SSize_t size = AvFILLp(av) + 1; + /* The ternary gives consistency with av_extend() */ + AV *newav = newAV_alloc_xz(size < 4 ? 4 : size); AvREIFY_only(newav); PAD_SVl(0) = MUTABLE_SV(newav); SvREFCNT_dec_NN(av); |