Skip to content

Commit

Permalink
av_create_and_push/unshift_one: faster create via newAV_alloc_xz
Browse files Browse the repository at this point in the history
  • Loading branch information
richardleach authored and khwilliamson committed Jul 31, 2021
1 parent 541e9af commit 71ca71b
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions av.c
Expand Up @@ -638,9 +638,11 @@ Perl_av_create_and_push(pTHX_ AV **const avp, SV *const val)
{
PERL_ARGS_ASSERT_AV_CREATE_AND_PUSH;

if (!*avp)
*avp = newAV();
av_push(*avp, val);
if (!*avp) {
*avp = newAV_alloc_xz(4);
AvARRAY(*avp)[ ++AvFILLp(*avp) ] = val;
} else
av_push(*avp, val);
}

/*
Expand Down Expand Up @@ -727,10 +729,14 @@ Perl_av_create_and_unshift_one(pTHX_ AV **const avp, SV *const val)
{
PERL_ARGS_ASSERT_AV_CREATE_AND_UNSHIFT_ONE;

if (!*avp)
*avp = newAV();
av_unshift(*avp, 1);
return av_store(*avp, 0, val);
if (!*avp) {
*avp = newAV_alloc_xz(4);
AvARRAY(*avp)[ ++AvFILLp(*avp) ] = val;
return val;
} else {
av_unshift(*avp, 1);
return av_store(*avp, 0, val);
}
}

/*
Expand Down

0 comments on commit 71ca71b

Please sign in to comment.