Commit 487f10e129 for perl
commit 487f10e1295f4e759e11a7a7195adcf997731a22
Author: David Mitchell <davem@iabyn.nospamdeletethisbit.com>
Date: Thu Oct 15 21:35:33 2026 +0100
regmatch: refactor: remove EVAL/GOSUB shared vars
Currently there is a block scope around the GOSUB and EVAL branches
with some variable declarations which are shared between both branches.
This commit eliminates those variables and shared scope, making the code
simpler and more comprehensible.
re_sv - was already only used in the EVAL branch. This commit just moves
the start of an EVAL block scope slightly earlier so that re_sv is
totally within that block.
startpoint - this is the new start node to pass to the shared
PUSH_YES_STATE_GOTO() call. Just set scan instead.
arg - this is only used by the GOSUB branch. Add a block scope to the
GOSUB branch instead and declare the variable there.
Also: re, rei - move their declarations to where they are first used.
diff --git a/regexec.c b/regexec.c
index fb189d6504..21210bb964 100644
--- a/regexec.c
+++ b/regexec.c
@@ -9168,13 +9168,9 @@ S_regmatch(pTHX_ regmatch_info *reginfo, char *startpos, regnode *prog)
#define ST st->u.eval
#define CUR_EVAL cur_eval->u.eval
- {
- REGEXP *re_sv;
- regnode *startpoint;
- U32 arg;
-
case GOSUB: /* /(...(?1))/ /(...(?&foo))/ */
- arg = GOSUB_CAPTURE(scan);
+ {
+ U32 arg = GOSUB_CAPTURE(scan);
if (cur_eval && cur_eval->locinput == locinput) {
if ( ++nochange_depth > max_nochange_depth )
croak(
@@ -9183,7 +9179,7 @@ S_regmatch(pTHX_ regmatch_info *reginfo, char *startpos, regnode *prog)
} else {
nochange_depth = 0;
}
- startpoint = scan + GOSUB_TARGET_OFFSET(scan);
+ scan += GOSUB_TARGET_OFFSET(scan);
EVAL_CLOSE_PAREN_SET( st, arg );
/* Detect infinite recursion
*
@@ -9220,6 +9216,7 @@ S_regmatch(pTHX_ regmatch_info *reginfo, char *startpos, regnode *prog)
/* and then jump to the code we share with EVAL */
goto eval_recurse_doit;
/* NOTREACHED */
+ }
case EVAL: /* /(?{...})B/ /(??{A})B/ and /(?(?{...})X|Y)B/ */
if (logical == 2 && cur_eval && cur_eval->locinput == locinput) {
@@ -9245,9 +9242,10 @@ S_regmatch(pTHX_ regmatch_info *reginfo, char *startpos, regnode *prog)
sv_setsv(sv_mrk, sv_yes_mark);
}
+ {
/* execute the (?{...}) code block and do some basic
* processing of the return value */
- re_sv = S_run_code_block(aTHX_ rex, reginfo,
+ REGEXP *re_sv = S_run_code_block(aTHX_ rex, reginfo,
orig_savestack_ix, logical, EVAL_CODE_DATA_SLOT(scan));
/* restore paren state */
@@ -9267,10 +9265,6 @@ S_regmatch(pTHX_ regmatch_info *reginfo, char *startpos, regnode *prog)
/* only /(??{ ... })/ from now on */
logical = 0;
- {
- regexp *re;
- regexp_internal *rei;
-
/* extract RE object from returned value; compiling if
* necessary */
@@ -9311,7 +9305,7 @@ S_regmatch(pTHX_ regmatch_info *reginfo, char *startpos, regnode *prog)
}
}
SAVEFREESV(re_sv);
- re = ReANY(re_sv);
+ regexp *re = ReANY(re_sv);
RXp_MATCH_COPIED_off(re);
RXp_SUBBEG(re) = RXp_SUBBEG(rex);
@@ -9320,12 +9314,12 @@ S_regmatch(pTHX_ regmatch_info *reginfo, char *startpos, regnode *prog)
RXp_SUBCOFFSET(re) = RXp_SUBCOFFSET(rex);
RXp_LASTPAREN(re) = 0;
RXp_LASTCLOSEPAREN(re) = 0;
- rei = RXi_GET(re);
+ regexp_internal *rei = RXi_GET(re);
DEBUG_EXECUTE_r(
debug_start_match(re_sv, utf8_target, locinput,
reginfo->strend, "deferred EVAL: Matching embedded");
);
- startpoint = rei->program + 1;
+ scan = rei->program + 1;
ST.prev_rex = rex_sv;
rex_sv = re_sv;
rex = re;
@@ -9364,10 +9358,9 @@ S_regmatch(pTHX_ regmatch_info *reginfo, char *startpos, regnode *prog)
depth, cur_eval, ST.prev_eval);
});
/* now continue from first node in postoned RE */
- PUSH_YES_STATE_GOTO(EVAL_postponed_A, startpoint, locinput,
+ PUSH_YES_STATE_GOTO(EVAL_postponed_A, scan, locinput,
loceol, script_run_begin);
NOT_REACHED; /* NOTREACHED */
- }
case EVAL_postponed_A: /* cleanup the A part after a
successful (??{A})B */