diff options
author | Andreas Rumpf <rumpf_a@web.de> | 2016-10-24 19:07:30 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-10-24 19:07:30 +0200 |
commit | 3715a5ac91ede3002a3d94dbab2926d96d5ff257 (patch) | |
tree | 3ec37d7f18b2d38d9c4f908b66dbf134fddd8c72 /lib/impure | |
parent | 56181da2045ed0ec5d67868cfd428c1b5c26455c (diff) | |
parent | dbef9f97c2efe38b9cb39130567f56df907785d3 (diff) | |
download | Nim-3715a5ac91ede3002a3d94dbab2926d96d5ff257.tar.gz |
Merge pull request #4814 from scriptum/rpg-pcre-jit
Enable JIT in PCRE to improve regular expressions performance
Diffstat (limited to 'lib/impure')
-rw-r--r-- | lib/impure/nre.nim | 8 | ||||
-rw-r--r-- | lib/impure/re.nim | 9 |
2 files changed, 13 insertions, 4 deletions
diff --git a/lib/impure/nre.nim b/lib/impure/nre.nim index 557bb0549..626c3fd6b 100644 --- a/lib/impure/nre.nim +++ b/lib/impure/nre.nim @@ -431,8 +431,12 @@ proc initRegex(pattern: string, flags: int, study = true): Regex = raise SyntaxError(msg: $errorMsg, pos: errOffset, pattern: pattern) if study: - # XXX investigate JIT - result.pcreExtra = pcre.study(result.pcreObj, 0x0, addr errorMsg) + var options: cint = 0 + var hasJit: cint + if pcre.config(pcre.CONFIG_JIT, addr hasJit) == 0: + if hasJit == 1'i32: + options = pcre.STUDY_JIT_COMPILE + result.pcreExtra = pcre.study(result.pcreObj, options, addr errorMsg) if errorMsg != nil: raise StudyError(msg: $errorMsg) diff --git a/lib/impure/re.nim b/lib/impure/re.nim index bd86bcdcf..f7f7c5b25 100644 --- a/lib/impure/re.nim +++ b/lib/impure/re.nim @@ -87,7 +87,12 @@ proc re*(s: string, flags = {reExtended, reStudy}): Regex = result.h = rawCompile(s, cast[cint](flags - {reStudy})) if reStudy in flags: var msg: cstring - result.e = pcre.study(result.h, 0, addr msg) + var options: cint = 0 + var hasJit: cint + if pcre.config(pcre.CONFIG_JIT, addr hasJit) == 0: + if hasJit == 1'i32: + options = pcre.STUDY_JIT_COMPILE + result.e = pcre.study(result.h, options, addr msg) if not isNil(msg): raiseInvalidRegex($msg) proc matchOrFind(s: string, pattern: Regex, matches: var openArray[string], @@ -214,7 +219,7 @@ proc find*(s: string, pattern: Regex, start = 0): int = var rtarray = initRtArray[cint](3) rawMatches = rtarray.getRawData - res = pcre.exec(pattern.h, nil, s, len(s).cint, start.cint, 0'i32, + res = pcre.exec(pattern.h, pattern.e, s, len(s).cint, start.cint, 0'i32, cast[ptr cint](rawMatches), 3) if res < 0'i32: return res return rawMatches[0] |