diff options
| author | Ganesh Viswanathan <dev@genotrance.com> | 2018-12-04 13:24:49 -0600 |
|---|---|---|
| committer | Ganesh Viswanathan <dev@genotrance.com> | 2018-12-04 13:24:49 -0600 |
| commit | cf2f200a16203311a3ac7595eb547b37fab5df82 (patch) | |
| tree | c3f6addc5caf4591d2d45599ac48034c6ccd1be9 | |
| parent | cb100ca5717ecc34112f1e5c5aac09439676c4ba (diff) | |
| download | nimterop-cf2f200a16203311a3ac7595eb547b37fab5df82.tar.gz nimterop-cf2f200a16203311a3ac7595eb547b37fab5df82.zip | |
Fix performance issues with regex
| -rw-r--r-- | nimterop/ast.nim | 5 | ||||
| -rw-r--r-- | nimterop/globals.nim | 3 | ||||
| -rw-r--r-- | nimterop/grammar.nim | 10 |
3 files changed, 14 insertions, 4 deletions
diff --git a/nimterop/ast.nim b/nimterop/ast.nim index ba7561e..df973b9 100644 --- a/nimterop/ast.nim +++ b/nimterop/ast.nim @@ -53,10 +53,7 @@ proc searchAstForNode(ast: ref Ast, node: TSNode): bool = return if ast.children.len != 0: - let - rstr = ast.getRegexForAstChildren() - - if childNames.contains(rstr.toPattern): + if childNames.contains(ast.regex): if node.getTSNodeNamedChildCountSansComments() != 0: var flag = true for i in 0 .. node.tsNodeNamedChildCount()-1: diff --git a/nimterop/globals.nim b/nimterop/globals.nim index 39969bc..e65a4b9 100644 --- a/nimterop/globals.nim +++ b/nimterop/globals.nim @@ -1,5 +1,7 @@ import tables +import regex + type Kind* = enum exactlyOne @@ -12,6 +14,7 @@ type kind*: Kind children*: seq[ref Ast] tonim*: proc () {.closure, locks: 0.} + regex*: Regex State* = object compile*, defines*, headers*, includeDirs*, searchDirs*: seq[string] diff --git a/nimterop/grammar.nim b/nimterop/grammar.nim index a07ad84..7876ca3 100644 --- a/nimterop/grammar.nim +++ b/nimterop/grammar.nim @@ -1,5 +1,7 @@ import strformat, tables +import regex + import "."/[getters, globals, lisp] proc initGrammar() = @@ -254,6 +256,13 @@ proc initGrammar() = )) +proc initRegex(ast: ref Ast) = + if ast.children.len != 0: + for child in ast.children: + child.initRegex() + + ast.regex = ast.getRegexForAstChildren().re() + proc parseGrammar*() = initGrammar() @@ -263,6 +272,7 @@ proc parseGrammar*() = ast = gStateRT.grammar[i].grammar.parseLisp() ast.tonim = gStateRT.grammar[i].call + ast.initRegex() if ast.name notin gStateRT.ast: gStateRT.ast[ast.name] = @[ast] else: |
