From ce59f6705d9b2bd6df0d3eeadbaf43b25fa58b4f Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Wed, 19 Oct 2011 00:01:18 +0200 Subject: parser caching (-> *great* speedup); generalized the yer-hack --- .../third/transliterator/trans_tables_gr.lua | 29 +++++++++++++++++----- 1 file changed, 23 insertions(+), 6 deletions(-) (limited to 'tex/context/third/transliterator/trans_tables_gr.lua') diff --git a/tex/context/third/transliterator/trans_tables_gr.lua b/tex/context/third/transliterator/trans_tables_gr.lua index 55b4c54..b4c77e7 100644 --- a/tex/context/third/transliterator/trans_tables_gr.lua +++ b/tex/context/third/transliterator/trans_tables_gr.lua @@ -2,7 +2,9 @@ -- Greek -- --===========================================================================-- -local translit = thirddata.translit +local translit = thirddata.translit +local pcache = translit.parser_cache +local lpegmatch = lpeg.match -- Note that the Greek transliteration mapping isn't bijective so transliterated -- texts won't be reversible. (Shouldn't be impossible to make one up using @@ -682,11 +684,26 @@ local function greek (mode, text) other = Cs(p / gr ), } - --g:print() - text = g:match(text) - return text + return g end end -translit.methods ["gr"] = function (text) return greek("gr" , text) end -translit.methods ["gr_n"] = function (text) return greek("gr_n", text) end +translit.methods["gr"] = function (text) + p = pcache["gr"] + if not p then + p = greek("gr") + pcache["gr"] = p + end + return lpegmatch(p, text) +end + +translit.methods["gr_n"] = function (text) + p = pcache["gr_n"] + if not p then + p = greek("gr_n") + pcache["gr_n"] = p + end + return lpegmatch(p, text) +end + +-- vim:ft=lua:sw=4:ts=4 -- cgit v1.2.3