letmut mat = None; letmut sid = dfa.start_state_forward(input)?; letmut at = input.start(); while at < input.end() {
sid = dfa.next_state(sid, input.haystack()[at]); if dfa.is_special_state(sid) { if dfa.is_match_state(sid) { let pattern = dfa.match_pattern(sid, 0);
mat = Some(HalfMatch::new(pattern, at)); if input.get_earliest() { return Ok(mat.ok_or(at));
} if dfa.is_accel_state(sid) { let needs = dfa.accelerator(sid);
at = accel::find_fwd(needs, input.haystack(), at)
.unwrap_or(input.end()); continue;
}
} elseif dfa.is_accel_state(sid) { let needs = dfa.accelerator(sid);
at = accel::find_fwd(needs, input.haystack(), at)
.unwrap_or(input.end()); continue;
} elseif dfa.is_dead_state(sid) { return Ok(mat.ok_or(at));
} elseif dfa.is_quit_state(sid) { if mat.is_some() { return Ok(mat.ok_or(at));
} return Err(MatchError::quit(input.haystack()[at], at).into());
} else { // Ideally we wouldn't use a DFA that specialized start states // and thus 'is_start_state()' could never be true here, but in // practice we reuse the DFA created for the full regex which // will specialize start states whenever there is a prefilter.
debug_assert!(dfa.is_start_state(sid));
}
}
at += 1;
}
dfa_eoi_fwd(dfa, input, &mut sid, &mut mat)?;
Ok(mat.ok_or(at))
}
#[cfg(feature = "hybrid")] pub(crate) fn hybrid_try_search_half_fwd(
dfa: &crate::hybrid::dfa::DFA,
cache: &mutcrate::hybrid::dfa::Cache,
input: &Input<'_>,
) -> Result<Result<HalfMatch, usize>, RetryFailError> { letmut mat = None; letmut sid = dfa.start_state_forward(cache, input)?; letmut at = input.start(); while at < input.end() {
sid = dfa
.next_state(cache, sid, input.haystack()[at])
.map_err(|_| MatchError::gave_up(at))?; if sid.is_tagged() { if sid.is_match() { let pattern = dfa.match_pattern(cache, sid, 0);
mat = Some(HalfMatch::new(pattern, at)); if input.get_earliest() { return Ok(mat.ok_or(at));
}
} elseif sid.is_dead() { return Ok(mat.ok_or(at));
} elseif sid.is_quit() { if mat.is_some() { return Ok(mat.ok_or(at));
} return Err(MatchError::quit(input.haystack()[at], at).into());
} else { // We should NEVER get an unknown state ID back from // dfa.next_state().
debug_assert!(!sid.is_unknown()); // Ideally we wouldn't use a lazy DFA that specialized start // states and thus 'sid.is_start()' could never be true here, // but in practice we reuse the lazy DFA created for the full // regex which will specialize start states whenever there is // a prefilter.
debug_assert!(sid.is_start());
}
}
at += 1;
}
hybrid_eoi_fwd(dfa, cache, input, &mut sid, &mut mat)?;
Ok(mat.ok_or(at))
}
let sp = input.get_span(); match input.haystack().get(sp.end) {
Some(&b) => {
*sid = dfa.next_state(*sid, b); if dfa.is_match_state(*sid) { let pattern = dfa.match_pattern(*sid, 0);
*mat = Some(HalfMatch::new(pattern, sp.end));
} elseif dfa.is_quit_state(*sid) { if mat.is_some() { return Ok(());
} return Err(MatchError::quit(b, sp.end));
}
}
None => {
*sid = dfa.next_eoi_state(*sid); if dfa.is_match_state(*sid) { let pattern = dfa.match_pattern(*sid, 0);
*mat = Some(HalfMatch::new(pattern, input.haystack().len()));
} // N.B. We don't have to check 'is_quit' here because the EOI // transition can never lead to a quit state.
debug_assert!(!dfa.is_quit_state(*sid));
}
}
Ok(())
}
#[cfg(feature = "hybrid")] #[cfg_attr(feature = "perf-inline", inline(always))] fn hybrid_eoi_fwd(
dfa: &crate::hybrid::dfa::DFA,
cache: &mutcrate::hybrid::dfa::Cache,
input: &Input<'_>,
sid: &mutcrate::hybrid::LazyStateID,
mat: &mut Option<HalfMatch>,
) -> Result<(), MatchError> { let sp = input.get_span(); match input.haystack().get(sp.end) {
Some(&b) => {
*sid = dfa
.next_state(cache, *sid, b)
.map_err(|_| MatchError::gave_up(sp.end))?; if sid.is_match() { let pattern = dfa.match_pattern(cache, *sid, 0);
*mat = Some(HalfMatch::new(pattern, sp.end));
} elseif sid.is_quit() { if mat.is_some() { return Ok(());
} return Err(MatchError::quit(b, sp.end));
}
}
None => {
*sid = dfa
.next_eoi_state(cache, *sid)
.map_err(|_| MatchError::gave_up(input.haystack().len()))?; if sid.is_match() { let pattern = dfa.match_pattern(cache, *sid, 0);
*mat = Some(HalfMatch::new(pattern, input.haystack().len()));
} // N.B. We don't have to check 'is_quit' here because the EOI // transition can never lead to a quit state.
debug_assert!(!sid.is_quit());
}
}
Ok(())
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.11 Sekunden
(vorverarbeitet am 2026-06-23)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.