Commit b5adff587c for perl
commit b5adff587ca649413b70b00cf3ea3cec7be13f98
Author: Richard Leach <rich+perl@hyphen-dash-hyphen.info>
Date: Sat Oct 24 22:37:21 2026 +0000
S_cleanup_regmatch_info_aux: eval_state is UNLIKELY
In many applications, use of the `eval_state` is likely to be uncommon.
gcov counters show that it certainly is rare in the test harness:
125305444:11836: if (eval_state) {
-:11837:
-:11838: /* undo the effects of S_setup_eval_state() */
-:11839:
5199:11840: if (eval_state->subbeg_flags & EVAL_STATE_HAS_SUBBEG) {
That branch is quite chunky, so making it `UNLIKELY()` will hopefully
help the compiler to streamline instruction ordering to benefit
regexes that don't use `eval_state`.
For any hot regexes that do use `eval_state`, there's enough work in
the branch that the impact of an unfavorable layout will hopefully be
very minimal.
Initialization of `eval_state` now occurs just before use, to help
compilers avoid allocating an additional register to store it
across the super-linear-cache work.
diff --git a/regexec.c b/regexec.c
index d904893332..a4499f9fca 100644
--- a/regexec.c
+++ b/regexec.c
@@ -11806,7 +11806,7 @@ static void
S_cleanup_regmatch_info_aux(pTHX_ void *arg)
{
regmatch_info_aux *aux = (regmatch_info_aux *) arg;
- regmatch_info_aux_eval *eval_state = aux->info_aux_eval;
+ regmatch_info_aux_eval *eval_state;
regexp_internal *rexi = aux->rexi;
regmatch_slab *s;
@@ -11833,7 +11833,8 @@ S_cleanup_regmatch_info_aux(pTHX_ void *arg)
Safefree(slc);
}
- if (eval_state) {
+ eval_state = aux->info_aux_eval;
+ if (UNLIKELY(eval_state)) {
/* undo the effects of S_setup_eval_state() */