summary refs log tree commit diff stats
path: root/src/nre.nim
diff options
context:
space:
mode:
authorFlaviu Tamas <tamasflaviu@gmail.com>2015-04-12 10:33:21 -0400
committerFlaviu Tamas <tamasflaviu@gmail.com>2015-04-12 10:33:21 -0400
commit90d17c4e03fe0a7ad1567bf9755d8ba836220cd7 (patch)
treeddd794f0421b0a877868303ef1229fa1e384656d /src/nre.nim
parent8b8224ecaf7ed8cfbe1a205b43c3402aabc1653f (diff)
downloadNim-90d17c4e03fe0a7ad1567bf9755d8ba836220cd7.tar.gz
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!
Diffstat (limited to 'src/nre.nim')
-rw-r--r--src/nre.nim2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/nre.nim b/src/nre.nim
index fbfe7deb1..b960bdc92 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)