Commit 41a15b103b for perl
commit 41a15b103b83133f8363da695cf113392ae313cb
Author: David Mitchell <davem@iabyn.nospamdeletethisbit.com>
Date: Tue Oct 27 09:58:39 2026 +0000
regex: refactor: tweak S_run_code_block()
Minor tweaks to the just-added S_run_code_block() function (the actual
code is old, it was just moved into its own function), based on
suggestions by Tony C.
- move the 'before', 'ret' and 'gimme' variable declarations closer to
their point of first use;
- make 'before' and 'gimme' const, since their value is only calculated
once;
- make 'before' ptrdiff_t as it holds the difference between two
pointers.
- add an assert(logical == 2)
diff --git a/regexec.c b/regexec.c
index b377cff66a..2a146bb95c 100644
--- a/regexec.c
+++ b/regexec.c
@@ -6962,13 +6962,10 @@ S_run_code_block(pTHX_ regexp *rex, regmatch_info *reginfo,
/* execute the code in the {...} */
dSP;
- IV before;
OP * const oop = PL_op;
COP * const ocurcop = PL_curcop;
OP *nop;
CV *newcv;
- SV *ret;
- U8 gimme = G_SCALAR;
RXi_GET_DECL(rex, rexi);
#ifdef DEBUGGING
@@ -7054,6 +7051,7 @@ S_run_code_block(pTHX_ regexp *rex, regmatch_info *reginfo,
CHANGE_MULTICALL_FLAGS_PREFIX_(newcv, flags, reginfo->);
}
else {
+ const U8 gimme = G_SCALAR;
PUSH_MULTICALL_FLAGS_PREFIX_(newcv, flags, reginfo->);
}
/* see notes above */
@@ -7106,11 +7104,12 @@ S_run_code_block(pTHX_ regexp *rex, regmatch_info *reginfo,
* first op of the block of interest, rather than the
* first op of the sub. Also, we don't want to free
* the savestack frame */
- before = (IV)(SP-PL_stack_base);
+ const ptrdiff_t before = SP-PL_stack_base;
PL_op = nop;
CALLRUNOPS(aTHX); /* Scalar context. */
SPAGAIN;
- if ((IV)(SP-PL_stack_base) == before)
+ SV *ret;
+ if (SP-PL_stack_base == before)
ret = &PL_sv_undef; /* protect against empty (?{}) blocks. */
else {
ret = POPs;
@@ -7134,6 +7133,7 @@ S_run_code_block(pTHX_ regexp *rex, regmatch_info *reginfo,
ret = NULL;
}
else { /* /(??{ ... }) */
+ assert(logical == 2);
/* if its overloaded, let the regex compiler handle
* it; otherwise extract regex, or stringify */
if (SvGMAGICAL(ret))