summaryrefslogtreecommitdiff
path: root/pp_hot.c
diff options
context:
space:
mode:
authorRichard Leach <richardleach@users.noreply.github.com>2021-04-19 21:28:01 +0100
committerHugo van der Sanden <hv@crypt.org>2021-05-26 13:42:43 +0100
commitd2a9e960038ce8485fc1eb7b94297c9e5b0a4033 (patch)
tree0032b2e59ac1fc6d36036eca4de9ca96d8cd2bd0 /pp_hot.c
parent0b1c19ab1cbed9c221a41fca38580344778ce3a6 (diff)
downloadperl-d2a9e960038ce8485fc1eb7b94297c9e5b0a4033.tar.gz
Perl_clear_defarray: faster array creation via new macro+function
Diffstat (limited to 'pp_hot.c')
-rw-r--r--pp_hot.c7
1 files changed, 3 insertions, 4 deletions
diff --git a/pp_hot.c b/pp_hot.c
index 3348afedf1..f89dea12fd 100644
--- a/pp_hot.c
+++ b/pp_hot.c
@@ -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);