diff options
author | Daniel Silverstone <dsilvers@digital-scurf.org> | 2014-03-22 12:13:10 +0000 |
---|---|---|
committer | Daniel Silverstone <dsilvers@digital-scurf.org> | 2014-03-22 12:13:10 +0000 |
commit | 4cec5510089783f34f69206f990cb34c5d57dcb8 (patch) | |
tree | d3f02db3b071e2ef2b2cf898d923496c5e7c4950 | |
parent | b79a19ca1f3f87a14f55257fad3c1ec47e6a36ea (diff) | |
download | lace-4cec5510089783f34f69206f990cb34c5d57dcb8.tar.gz |
Attempt caching of lexed lines to speed things up
-rw-r--r-- | lib/lace/lex.lua | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/lib/lace/lex.lua b/lib/lace/lex.lua index 1085bed..af891af 100644 --- a/lib/lace/lex.lua +++ b/lib/lace/lex.lua @@ -15,7 +15,7 @@ local M = {} -local function lex_one_line(line) +local function _lex_one_line(line) local r = {} local acc = "" local c @@ -91,6 +91,15 @@ local function lex_one_line(line) return r, warnings end +local lexer_line_cache = {} + +local function lex_one_line(line) + if not lexer_line_cache[line] then + lexer_line_cache[line] = { _lex_one_line(line) } + end + return lexer_line_cache[line][1], lexer_line_cache[line][2] +end + --- Lexically analyse a ruleset. -- @tparam string ruleset The ruleset to lex. -- @tparam string sourcename The name of the source to go into debug info. |