From 90d17c4e03fe0a7ad1567bf9755d8ba836220cd7 Mon Sep 17 00:00:00 2001 From: Flaviu Tamas Date: Sun, 12 Apr 2015 10:33:21 -0400 Subject: [PATCH] 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! --- src/nre.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nre.nim b/src/nre.nim index fbfe7deb10..b960bdc929 100644 --- a/src/nre.nim +++ b/src/nre.nim @@ -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)