In perl.git, the branch blead has been updated <http://perl5.git.perl.org/perl.git/commitdiff/7e169e8432077cbdaf237f7238ca7a40fe1116ac?hp=c55dd03d1d6eb39244430d1cf2e0e94240d2b37a>
- Log ----------------------------------------------------------------- commit 7e169e8432077cbdaf237f7238ca7a40fe1116ac Author: David Mitchell <da...@iabyn.com> Date: Sun Jun 26 23:13:00 2016 +0100 pp_aelemfast: skip av_fetch() for simple cases Where the av is non magic and has a positive key, try fetching the array element directly rather than calling av_fetch(). This reduces the number of cycles required to run the nbody benchmark by about 5%. ----------------------------------------------------------------------- Summary of changes: pp_hot.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/pp_hot.c b/pp_hot.c index 223169b..9c547d4 100644 --- a/pp_hot.c +++ b/pp_hot.c @@ -819,11 +819,27 @@ PP(pp_aelemfast) AV * const av = PL_op->op_type == OP_AELEMFAST_LEX ? MUTABLE_AV(PAD_SV(PL_op->op_targ)) : GvAVn(cGVOP_gv); const U32 lval = PL_op->op_flags & OPf_MOD; - SV** const svp = av_fetch(av, (I8)PL_op->op_private, lval); - SV *sv = (svp ? *svp : &PL_sv_undef); + const I8 key = (I8)PL_op->op_private; + SV** svp; + SV *sv; + + assert(SvTYPE(av) == SVt_PVAV); + + /* inlined av_fetch() for simple cases ... */ + if (!SvRMAGICAL(av) && key >= 0 && key <= AvFILLp(av)) { + sv = AvARRAY(av)[key]; + if (sv && !SvIS_FREED(sv)) { + PUSHs(sv); + RETURN; + } + } + + /* ... else do it the hard way */ + svp = av_fetch(av, key, lval); + sv = (svp ? *svp : &PL_sv_undef); if (UNLIKELY(!svp && lval)) - DIE(aTHX_ PL_no_aelem, (int)(I8)PL_op->op_private); + DIE(aTHX_ PL_no_aelem, (int)key); EXTEND(SP, 1); if (!lval && SvRMAGICAL(av) && SvGMAGICAL(sv)) /* see note in pp_helem() */ -- Perl5 Master Repository