Skip to content

Commit eb7b270

Browse files
committed
expand tryAMAGICunTARGETlist() macro
This long macro is only used in two places (pp_readline and pp_glob). Expand the contents of this macro directly in those two functions. This will make it easier to individually unwrap (i.e. remove PP_wrapped()) those two functions. Shouldn't be any functional change.
1 parent ebb1b1f commit eb7b270

File tree

3 files changed

+80
-2
lines changed

3 files changed

+80
-2
lines changed

pp.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,8 @@ Does not use C<TARG>. See also C<L</XPUSHu>>, C<L</mPUSHu>> and C<L</PUSHu>>.
681681
/* No longer used in core. Use AMG_CALLunary instead */
682682
#define AMG_CALLun(sv,meth) AMG_CALLunary(sv, CAT2(meth,_amg))
683683

684+
/* No longer used in core. Was expanded directly into its only two users,
685+
* pp_readline and pp_glob */
684686
#define tryAMAGICunTARGETlist(meth, jump) \
685687
STMT_START { \
686688
dSP; \

pp_hot.c

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1497,7 +1497,41 @@ PP_wrapped(pp_readline, ((PL_op->op_flags & OPf_STACKED) ? 2 : 1), 0)
14971497
* CORE::readline() */
14981498
if (TOPs) {
14991499
SvGETMAGIC(TOPs);
1500-
tryAMAGICunTARGETlist(iter_amg, 0);
1500+
1501+
/* unrolled tryAMAGICunTARGETlist(iter_amg, 0) */
1502+
SV *tmpsv;
1503+
SV *arg= *sp;
1504+
U8 gimme = GIMME_V;
1505+
if (UNLIKELY(SvAMAGIC(arg) &&
1506+
(tmpsv = amagic_call(arg, &PL_sv_undef, iter_amg,
1507+
AMGf_want_list | AMGf_noright
1508+
|AMGf_unary))))
1509+
{
1510+
SPAGAIN;
1511+
if (gimme == G_VOID) {
1512+
NOOP;
1513+
}
1514+
else if (gimme == G_LIST) {
1515+
SSize_t i;
1516+
SSize_t len;
1517+
assert(SvTYPE(tmpsv) == SVt_PVAV);
1518+
len = av_count((AV *)tmpsv);
1519+
(void)POPs; /* get rid of the arg */
1520+
EXTEND(sp, len);
1521+
for (i = 0; i < len; ++i)
1522+
PUSHs(av_shift((AV *)tmpsv));
1523+
}
1524+
else { /* AMGf_want_scalar */
1525+
dATARGET; /* just use the arg's location */
1526+
sv_setsv(TARG, tmpsv);
1527+
if (PL_op->op_flags & OPf_STACKED)
1528+
sp--;
1529+
SETTARG;
1530+
}
1531+
PUTBACK;
1532+
return NORMAL;
1533+
}
1534+
15011535
PL_last_in_gv = MUTABLE_GV(*PL_stack_sp--);
15021536
}
15031537
else PL_last_in_gv = PL_argvgv, PL_stack_sp--;

pp_sys.c

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,49 @@ PP_wrapped(pp_glob, 1 + !(PL_op->op_flags & OPf_SPECIAL), 0)
351351
* is called once and only once */
352352
if (SvGMAGICAL(TOPs)) TOPs = sv_2mortal(newSVsv(TOPs));
353353

354-
tryAMAGICunTARGETlist(iter_amg, (PL_op->op_flags & OPf_SPECIAL));
354+
/* unrolled
355+
tryAMAGICunTARGETlist(iter_amg, (PL_op->op_flags & OPf_SPECIAL)); */
356+
SV *tmpsv;
357+
SV *arg= *sp;
358+
U8 gimme = GIMME_V;
359+
if (UNLIKELY(SvAMAGIC(arg) &&
360+
(tmpsv = amagic_call(arg, &PL_sv_undef, iter_amg,
361+
AMGf_want_list | AMGf_noright
362+
|AMGf_unary))))
363+
{
364+
SPAGAIN;
365+
if (gimme == G_VOID) {
366+
NOOP;
367+
}
368+
else if (gimme == G_LIST) {
369+
SSize_t i;
370+
SSize_t len;
371+
assert(SvTYPE(tmpsv) == SVt_PVAV);
372+
len = av_count((AV *)tmpsv);
373+
(void)POPs; /* get rid of the arg */
374+
EXTEND(sp, len);
375+
for (i = 0; i < len; ++i)
376+
PUSHs(av_shift((AV *)tmpsv));
377+
}
378+
else { /* AMGf_want_scalar */
379+
dATARGET; /* just use the arg's location */
380+
sv_setsv(TARG, tmpsv);
381+
if (PL_op->op_flags & OPf_STACKED)
382+
sp--;
383+
SETTARG;
384+
}
385+
PUTBACK;
386+
if (PL_op->op_flags & OPf_SPECIAL) {
387+
OP *jump_o = NORMAL->op_next;
388+
while (jump_o->op_type == OP_NULL)
389+
jump_o = jump_o->op_next;
390+
assert(jump_o->op_type == OP_ENTERSUB);
391+
(void)POPMARK;
392+
return jump_o->op_next;
393+
}
394+
return NORMAL;
395+
}
396+
355397

356398
if (PL_op->op_flags & OPf_SPECIAL) {
357399
/* call Perl-level glob function instead. Stack args are:

0 commit comments

Comments
 (0)