From b1422d62a2c3dcf265ea32d11c493769631aeaed Mon Sep 17 00:00:00 2001 From: David Mitchell Date: Wed, 31 Jul 2013 10:13:31 +0100 Subject: [PATCH] pp_match(): only look up pos() magic once Currently before matching, we see whether the SV has any pos() magic attached; then after the match we look it up again to update pos(). Instead just remember the previous value of mg and reuse it where possible. --- pp_hot.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/pp_hot.c b/pp_hot.c index d7de38a8e0e6..c3977997dc37 100644 --- a/pp_hot.c +++ b/pp_hot.c @@ -1332,6 +1332,7 @@ PP(pp_match) STRLEN len; const I32 oldsave = PL_savestack_ix; I32 had_zerolen = 0; + MAGIC *mg = NULL; if (PL_op->op_flags & OPf_STACKED) TARG = POPs; @@ -1385,7 +1386,7 @@ PP(pp_match) /* get pos() if //g */ if (global) { - MAGIC * const mg = mg_find_mglob(TARG); + mg = mg_find_mglob(TARG); if (mg && mg->mg_len >= 0) { curpos = mg->mg_len; /* last time pos() was set, it was zero-length match */ @@ -1443,10 +1444,8 @@ PP(pp_match) /* update pos */ if (global && (gimme != G_ARRAY || (dynpm->op_pmflags & PMf_CONTINUE))) { - MAGIC *mg = mg_find_mglob(TARG); - if (!mg) { + if (!mg) mg = sv_magicext_mglob(TARG); - } mg->mg_len = RX_OFFS(rx)[0].end; if (RX_ZERO_LEN(rx)) mg->mg_flags |= MGf_MINMATCH; @@ -1498,9 +1497,10 @@ PP(pp_match) nope: if (global && !(dynpm->op_pmflags & PMf_CONTINUE)) { - MAGIC* const mg = mg_find_mglob(TARG); - if (mg) - mg->mg_len = -1; + if (!mg) + mg = mg_find_mglob(TARG); + if (mg) + mg->mg_len = -1; } LEAVE_SCOPE(oldsave); if (gimme == G_ARRAY)