Skip to content

Commit

Permalink
pp_match(): only look up pos() magic once
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
iabyn committed Jul 31, 2013
1 parent adf5188 commit b1422d6
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions pp_hot.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit b1422d6

Please sign in to comment.