Skip to content

Commit 8a8d599

Browse files
committed
automata/meta: tweak reverse suffix prefilter strategy
Previously, we were only use the reverse suffix optimization if it found a non-empty longest common suffix *and* if the prefilter thought itself was fast. This was a heuristic used in the old regex crate before we grew the "is prefilter fast" heuristic. We change this optimization to just use the "is prefilter fast" heuristic instead of requiring a non-empty longest common suffix. This is, after all, what the inner literal optimization does. And in the inner literal case, one should probably be even more conservative because of the extra work that needs to be done. So if things are going okay with the inner literal optimization, then we should be fine with the reverse suffix optimization doing essentially the same thing.
1 parent 04f5d7b commit 8a8d599

File tree

1 file changed

+12
-25
lines changed

1 file changed

+12
-25
lines changed

regex-automata/src/meta/strategy.rs

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,34 +1167,21 @@ impl ReverseSuffix {
11671167
return Err(core);
11681168
}
11691169
let kind = core.info.config().get_match_kind();
1170-
let suffixes = crate::util::prefilter::suffixes(kind, hirs);
1171-
let lcs = match suffixes.longest_common_suffix() {
1172-
None => {
1173-
debug!(
1174-
"skipping reverse suffix optimization because \
1175-
a longest common suffix could not be found",
1176-
);
1177-
return Err(core);
1178-
}
1179-
Some(lcs) if lcs.is_empty() => {
1180-
debug!(
1181-
"skipping reverse suffix optimization because \
1182-
the longest common suffix is the empty string",
1183-
);
1184-
return Err(core);
1185-
}
1186-
Some(lcs) => lcs,
1170+
let suffixseq = crate::util::prefilter::suffixes(kind, hirs);
1171+
let Some(suffixes) = suffixseq.literals() else {
1172+
debug!(
1173+
"skipping reverse suffix optimization because \
1174+
the extract suffix sequence is not finite",
1175+
);
1176+
return Err(core);
11871177
};
1188-
let pre = match Prefilter::new(kind, &[lcs]) {
1189-
Some(pre) => pre,
1190-
None => {
1191-
debug!(
1192-
"skipping reverse suffix optimization because \
1178+
let Some(pre) = Prefilter::new(kind, suffixes) else {
1179+
debug!(
1180+
"skipping reverse suffix optimization because \
11931181
a prefilter could not be constructed from the \
11941182
longest common suffix",
1195-
);
1196-
return Err(core);
1197-
}
1183+
);
1184+
return Err(core);
11981185
};
11991186
if !pre.is_fast() {
12001187
debug!(

0 commit comments

Comments
 (0)