is it faster to call find before calling captures? #803
-
Hi, I've been looking into the |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Good question. No, you definitely do not want to run The example in the |
Beta Was this translation helpful? Give feedback.
Good question. No, you definitely do not want to run
find
first, as the regex crate will actually do that for you. In cases where the DFA can't be used, then you would wind up making your total time twice as slow as you would just be running the NFA twice.The example in the
grep
crate is doing something different. The searcher only reports lines that match. So you have to run the regex again to find the bounds of each individual match, which is strictly more work. Finding the bounds of the line that matches can be done with less work via theshortest_match
method. Indeed, that is what the grep crates do internally.