This pull request introduces a new method, Automaton.any_match(string)
, to provide a high-performance interface for checking if any keyword exists within a given string.
Currently, the most direct way to perform an existence check is next(A.iter(text), None) is not None
. While functional, this pattern incurs overhead from the creation and state management of a Python-level iterator object. For high-throughput applications where only the presence of a match is needed, this overhead can be a bottleneck.
The any_match()
method is a stateless, C-level function that implements a true early-exit search. It avoids Python object allocation for iterators or results, returning a singleton Py_True
or Py_False
. This provides a significant performance gain, especially in scenarios where matches are found early in the input text.