@@ -1278,9 +1278,11 @@ impl PikeVM {
1278
1278
// Note: since capture groups are not allowed inside look-behinds,
1279
1279
// there won't be any Capture epsilon transitions and hence it is ok to
1280
1280
// use &mut [] for the slots parameter. We need to add the start states
1281
- // in reverse because nested look-behinds have a higher index but must
1282
- // be executed first.
1283
- for look_behind_start in self . nfa . look_behind_starts ( ) {
1281
+ // in reverse because more deeply nested look-behinds have a higher index
1282
+ // but must be executed first, so that the result is available for the
1283
+ // outer expression.
1284
+ for look_behind_start in self . nfa . look_behind_starts ( ) . iter ( ) . rev ( )
1285
+ {
1284
1286
self . epsilon_closure (
1285
1287
stack,
1286
1288
& mut [ ] ,
@@ -2091,8 +2093,10 @@ pub struct Cache {
2091
2093
curr_lookaround : ActiveStates ,
2092
2094
/// The next set of states to be explored for look-behind subexpressions.
2093
2095
next_lookaround : ActiveStates ,
2094
- /// The active set of states when a match was found. This is needed
2095
- /// to resume a search without recomputing look-behind subexpressions.
2096
+ /// The set of active threads, belonging to look-behind expressions,
2097
+ /// when a match was found. This is needed to resume a search after a match
2098
+ /// was found (to look for further matches), without having to re-scan the
2099
+ /// beginning of the haystack.
2096
2100
match_lookaround : Option < ActiveStates > ,
2097
2101
/// When true, use the states of `match_lookaround` to initialize a search,
2098
2102
/// otherwise recompute from the beginning of the haystack.
@@ -2168,12 +2172,13 @@ impl Cache {
2168
2172
self . keep_lookaround_state = false ;
2169
2173
}
2170
2174
2171
- /// Set this cache to keep the state of look-behind assertions upon a
2172
- /// match being found.
2175
+ /// Set this cache to store a copy of the active threads belonging
2176
+ /// to look-behind assertions upon a match being found.
2173
2177
///
2174
- /// This must only be called with a value of `true` when a new search is
2175
- /// started at the end of a previously found match, otherwise the result
2176
- /// of any search after this call will most likely be wrong.
2178
+ /// This is a performance optimization and must only be called with a
2179
+ /// value of `true` when intending to start a new search at the end of
2180
+ /// a previously found match. Otherwise, the result of look-behind
2181
+ /// sub-expressions will be out of sync with the main regex.
2177
2182
///
2178
2183
/// Calling this function with a value of `false` will clear any previously
2179
2184
/// stored look-behind state.
0 commit comments