Commit 10bbb31287 for perl
commit 10bbb31287c92670cd1aacd59bc44a593a602814
Author: David Mitchell <davem@iabyn.nospamdeletethisbit.com>
Date: Tue Oct 20 18:17:01 2026 +0100
regex: study_chunk: refactor: simplify flag copies
In study_chunk(), whenever it wants to recurse it creates a modified
copy of the current flags. The code currently looks a bit like this in
several places:
U32 f = (flags & SCF_FOO);
...
if (flags & SCF_BAR)
f |= SCF_BAR;
which is just an overly complex way of writing:
U32 f = (flags & (SCF_FOO|SCF_BAR));
So this commit changes it to the latter form.
diff --git a/regcomp_study.c b/regcomp_study.c
index 81718268e8..38195f73d7 100644
--- a/regcomp_study.c
+++ b/regcomp_study.c
@@ -1721,7 +1721,8 @@ Perl_study_chunk(pTHX_
while (OP(scan) == code) {
SSize_t deltanext, minnext, fake_last_close = 0;
regnode *fake_last_close_op = NULL;
- U32 f = (flags & SCF_TRIE_DOING_RESTUDY);
+ U32 f = (flags & (SCF_TRIE_DOING_RESTUDY
+ |SCF_WHILEM_VISITED_POS));
regnode_ssc this_class;
DEBUG_PEEP("Branch", scan, depth, flags);
@@ -1747,8 +1748,6 @@ Perl_study_chunk(pTHX_
data_fake.start_class = &this_class;
f |= SCF_DO_STCLASS_AND;
}
- if (flags & SCF_WHILEM_VISITED_POS)
- f |= SCF_WHILEM_VISITED_POS;
/* we suppose the run is continuous, last = next...*/
/* recurse study_chunk() for each BRANCH in an alternation */
@@ -3276,7 +3275,8 @@ Perl_study_chunk(pTHX_
regnode *cur_last_close_op;
regnode *nscan;
regnode_ssc intrnl;
- U32 f = (flags & SCF_TRIE_DOING_RESTUDY);
+ U32 f = (flags & (SCF_TRIE_DOING_RESTUDY
+ |SCF_WHILEM_VISITED_POS));
StructCopy(&zero_scan_data, &data_fake, scan_data_t);
if (data) {
@@ -3301,8 +3301,7 @@ Perl_study_chunk(pTHX_
data_fake.start_class = &intrnl;
f |= SCF_DO_STCLASS_AND;
}
- if (flags & SCF_WHILEM_VISITED_POS)
- f |= SCF_WHILEM_VISITED_POS;
+
next = regnext(scan);
nscan = REGNODE_AFTER(scan);
@@ -3390,7 +3389,8 @@ Perl_study_chunk(pTHX_
regnode *last_close_op = NULL;
regnode *nscan;
regnode_ssc intrnl;
- U32 f = (flags & SCF_TRIE_DOING_RESTUDY);
+ U32 f = (flags & (SCF_TRIE_DOING_RESTUDY
+ |SCF_WHILEM_VISITED_POS));
/* We use SAVEFREEPV so that when the full compile
is finished perl will clean up the allocated
minlens when it's all done. This way we don't
@@ -3426,8 +3426,6 @@ Perl_study_chunk(pTHX_
data_fake.start_class = &intrnl;
f |= SCF_DO_STCLASS_AND;
}
- if (flags & SCF_WHILEM_VISITED_POS)
- f |= SCF_WHILEM_VISITED_POS;
next = regnext(scan);
nscan = REGNODE_AFTER(scan);
@@ -3590,7 +3588,8 @@ Perl_study_chunk(pTHX_
for ( word = 1 ; word <= trie->wordcount ; word++)
{
SSize_t deltanext = 0, minnext = 0;
- U32 f = (flags & SCF_TRIE_DOING_RESTUDY);
+ U32 f = (flags & (SCF_TRIE_DOING_RESTUDY
+ |SCF_WHILEM_VISITED_POS));
SSize_t fake_last_close = 0;
regnode *fake_last_close_op = NULL;
regnode_ssc this_class;
@@ -3610,8 +3609,6 @@ Perl_study_chunk(pTHX_
data_fake.start_class = &this_class;
f |= SCF_DO_STCLASS_AND;
}
- if (flags & SCF_WHILEM_VISITED_POS)
- f |= SCF_WHILEM_VISITED_POS;
if (trie->jump[word]) {
if (!nextbranch)