Skip to content

Commit

Permalink
pp_unshift: av_store is often unnecessary
Browse files Browse the repository at this point in the history
  • Loading branch information
richardleach committed Jun 12, 2021
1 parent 7886147 commit 4563a42
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions pp.c
Expand Up @@ -5845,10 +5845,22 @@ PP(pp_unshift)

av_unshift(ary, SP - MARK);
PL_delaymagic = DM_DELAY;
while (MARK < SP) {
SV * const sv = newSVsv(*++MARK);
(void)av_store(ary, i++, sv);

if (!SvSMAGICAL(ary)) {
/* av_store is unnecessary, following the earlier av_unshift */
while (MARK < SP) {
SV * const sv = newSVsv(*++MARK);
assert(!AvREAL(ary) || AvARRAY(ary)[i] == NULL);
AvARRAY(ary)[i] = sv;
i++;
}
} else {
while (MARK < SP) {
SV * const sv = newSVsv(*++MARK);
(void)av_store(ary, i++, sv);
}
}

if (PL_delaymagic & DM_ARRAY_ISA)
mg_set(MUTABLE_SV(ary));
PL_delaymagic = old_delaymagic;
Expand Down

0 comments on commit 4563a42

Please sign in to comment.