Commit 911d00f8ca for perl

commit 911d00f8ca6af09ed8211de6d47b2fe3a71bfbe5
Author: David Mitchell <davem@iabyn.nospamdeletethisbit.com>
Date:   Thu Oct 15 20:32:35 2026 +0100

    regmatch: refactor: simplify setting new regex

    Both GOSUB (?1} and deferred EVAL (??{...}) execute a sub-pattern;
    the difference being that GOSUB re-uses the current pattern, while EVAL
    uses a new pattern. The shared code which currently handles this looks a
    bit like:

        {
            REGEXP *re_sv;

        case GOSUB:
            ...
            re_sv = rex_sv;
            goto eval_recurse_doit:

        case EVAL:
            re_sv = S_run_code_block(...);
            ...
          eval_recurse_doit:
            rex_sv = re_sv;
            ...
        }

    i.e. the common code updates the currently executing regex, rex_sv to
    the new value. Similar code sets rex, rexi which are derived from rex_sv.

    This commit simplifies the code to:

        {
            REGEXP *re_sv;

        case GOSUB:
            ...
            goto eval_recurse_doit:

        case EVAL:
            re_sv = S_run_code_block(...);
            ...
            rex_sv = re_sv;

          eval_recurse_doit:
            ...
        }

    and similarly for rex, rexi.

diff --git a/regexec.c b/regexec.c
index e2ea894585..f5430319c9 100644
--- a/regexec.c
+++ b/regexec.c
@@ -9170,8 +9170,6 @@ S_regmatch(pTHX_ regmatch_info *reginfo, char *startpos, regnode *prog)

         {
             REGEXP *re_sv;
-            regexp *re;
-            regexp_internal *rei;
             regnode *startpoint;
             U32 arg;

@@ -9185,9 +9183,6 @@ S_regmatch(pTHX_ regmatch_info *reginfo, char *startpos, regnode *prog)
             } else {
                 nochange_depth = 0;
             }
-            re_sv = rex_sv;
-            re = rex;
-            rei = rexi;
             startpoint = scan + GOSUB_TARGET_OFFSET(scan);
             EVAL_CLOSE_PAREN_SET( st, arg );
             /* Detect infinite recursion
@@ -9220,6 +9215,7 @@ S_regmatch(pTHX_ regmatch_info *reginfo, char *startpos, regnode *prog)
             /* Save all the positions seen so far. */
             ST.cp = regcppush(rex, 0, maxopenparen);
             REGCP_SET(ST.lastcp);
+            ST.prev_rex = rex_sv;

             /* and then jump to the code we share with EVAL */
             goto eval_recurse_doit;
@@ -9272,6 +9268,9 @@ 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 */

@@ -9313,7 +9312,6 @@ S_regmatch(pTHX_ regmatch_info *reginfo, char *startpos, regnode *prog)
                 }
                 SAVEFREESV(re_sv);
                 re = ReANY(re_sv);
-            }

             RXp_MATCH_COPIED_off(re);
             RXp_SUBBEG(re) = RXp_SUBBEG(rex);
@@ -9328,6 +9326,12 @@ S_regmatch(pTHX_ regmatch_info *reginfo, char *startpos, regnode *prog)
                                 reginfo->strend, "EVAL/GOSUB: Matching embedded");
             );
             startpoint = rei->program + 1;
+                ST.prev_rex = rex_sv;
+                rex_sv = re_sv;
+                rex = re;
+                rexi = rei;
+            }
+
             EVAL_CLOSE_PAREN_CLEAR(st); /* ST.close_paren = 0;
                                          * close_paren only for GOSUB */
             ST.prev_recurse_locinput= NULL; /* only used for GOSUB */
@@ -9347,14 +9351,10 @@ S_regmatch(pTHX_ regmatch_info *reginfo, char *startpos, regnode *prog)
             seen_nonregular = true;

             /* the new regexp might have a different is_utf8_pat than we do */
-            is_utf8_pat = reginfo->is_utf8_pat = cBOOL(RX_UTF8(re_sv));
+            is_utf8_pat = reginfo->is_utf8_pat = cBOOL(RX_UTF8(rex_sv));

-            ST.prev_rex = rex_sv;
             ST.prev_curlyx = cur_curlyx;
-            rex_sv = re_sv;
             S_set_reg_curpm(aTHX_ rex_sv, reginfo);
-            rex = re;
-            rexi = rei;
             cur_curlyx = NULL;
             ST.B = next;
             ST.prev_eval = cur_eval;