Improve performance
Removing ANCHORED means that after findIter is unable to find any more matches, it doesn't bother searching unless there are some promising 0-len matches. This significantly improves performance on problems like `"abccccccccccccc".find(re"a")`. Previously, each "c" would require a call to pcre_exec, which would iterate over [index_of_c..string.len], a O(n^2) process!
This commit is contained in:
parent
8b8224ecaf
commit
90d17c4e03
1 changed files with 1 additions and 1 deletions
|
|
@ -489,7 +489,7 @@ iterator findIter*(str: string, pattern: Regex, start = 0, endpos = int.high): R
|
|||
if match and
|
||||
match.get.matchBounds.a > match.get.matchBounds.b:
|
||||
# 0-len match
|
||||
flags = pcre.NOTEMPTY_ATSTART or pcre.ANCHORED
|
||||
flags = pcre.NOTEMPTY_ATSTART
|
||||
|
||||
match = str.matchImpl(pattern, offset, endpos, flags)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue