Skip to content

Commit eaa68d3

Browse files
committed
regex: don't LEAVE_SCOPE() in S_regtry()
This commit should produce no practical change in functionality. Currently, S_regtry() notes the position of PL_savestack_ix, calls S_regmatch(), then pops the savestack back to that position. However, S_regmatch() also does this just before returning, so it's redundant in S_regtry(). (A temporary assert confirmed that lastcp == PL_savestack_ix in S_regtry always while running the test suite). So this commit removes the REGCP_UNWIND(lastcp) and associated machinery from S_regtry(). It also regularises the "note current ix; pop back to old ix" code at the start and end of S_regmatch() to use the standard REGCP_SET() and REGCP_UNWIND() macros which do the same thing but also produce debugging messages.
1 parent 7ddc008 commit eaa68d3

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

regexec.c

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4408,13 +4408,9 @@ S_set_reg_curpm(pTHX_ REGEXP *rx, regmatch_info *reginfo)
44084408
STATIC bool /* 0 failure, 1 success */
44094409
S_regtry(pTHX_ regmatch_info *reginfo, char **startposp)
44104410
{
4411-
CHECKPOINT lastcp;
44124411
REGEXP *const rx = reginfo->prog;
44134412
regexp *const prog = ReANY(rx);
44144413
SSize_t result;
4415-
#ifdef DEBUGGING
4416-
U32 depth = 0; /* used by REGCP_SET */
4417-
#endif
44184414
RXi_GET_DECL(prog,progi);
44194415
DECLARE_AND_GET_RE_DEBUG_FLAGS;
44204416

@@ -4458,15 +4454,13 @@ S_regtry(pTHX_ regmatch_info *reginfo, char **startposp)
44584454
}
44594455
}
44604456
#endif
4461-
REGCP_SET(lastcp);
44624457
result = regmatch(reginfo, *startposp, progi->program + 1);
44634458
if (result != -1) {
44644459
RXp_OFFSp(prog)[0].end = result;
44654460
return 1;
44664461
}
44674462
if (reginfo->cutpoint)
44684463
*startposp= reginfo->cutpoint;
4469-
REGCP_UNWIND(lastcp);
44704464
return 0;
44714465
}
44724466

@@ -6712,7 +6706,7 @@ S_regmatch(pTHX_ regmatch_info *reginfo, char *startpos, regnode *prog)
67126706
char_class_number_ classnum;
67136707
bool is_utf8_pat = reginfo->is_utf8_pat;
67146708
bool match = false;
6715-
I32 orig_savestack_ix = PL_savestack_ix;
6709+
I32 orig_savestack_ix;
67166710
U8 * script_run_begin = NULL;
67176711
char *match_end= NULL; /* where a match MUST end to be considered successful */
67186712
bool is_accepted = false; /* have we hit an ACCEPT opcode? */
@@ -6747,6 +6741,8 @@ S_regmatch(pTHX_ regmatch_info *reginfo, char *startpos, regnode *prog)
67476741
Perl_re_printf( aTHX_ "regmatch start\n" );
67486742
}));
67496743

6744+
REGCP_SET(orig_savestack_ix);
6745+
67506746
while (scan != NULL) {
67516747
next = scan + NEXT_OFF(scan);
67526748
if (next == scan)
@@ -10399,8 +10395,9 @@ NULL
1039910395
POP_MULTICALL;
1040010396
PERL_UNUSED_VAR(SP);
1040110397
}
10402-
else
10403-
LEAVE_SCOPE(orig_savestack_ix);
10398+
else {
10399+
REGCP_UNWIND(orig_savestack_ix);
10400+
}
1040410401

1040510402
if ( reginfo->info_aux_eval
1040610403
&& reginfo->info_aux_eval->final_replsv)

0 commit comments

Comments
 (0)