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_scntfc.lua | 43 ++++++++++++++++++---- 1 file changed, 35 insertions(+), 8 deletions(-) (limited to 'tex/context/third/transliterator/trans_tables_scntfc.lua') diff --git a/tex/context/third/transliterator/trans_tables_scntfc.lua b/tex/context/third/transliterator/trans_tables_scntfc.lua index 904db71..ac5c398 100644 --- a/tex/context/third/transliterator/trans_tables_scntfc.lua +++ b/tex/context/third/transliterator/trans_tables_scntfc.lua @@ -2,7 +2,9 @@ -- Other transliterations -- --===========================================================================-- -local translit = thirddata.translit +local translit = thirddata.translit +local pcache = translit.parser_cache +local lpegmatch = lpeg.match -- The following are needed because ISO 9 does not cover old Slavonic -- characters that became obsolete before the advent of гражданский шрифт. @@ -201,7 +203,7 @@ end -- End Of Tables -- --===========================================================================-- -local function scientific (mode, text) +local function scientific (mode) local P, Cs = lpeg.P, lpeg.Cs local utfchar = translit.utfchar local addrules = translit.addrules @@ -221,7 +223,7 @@ local function scientific (mode, text) + translit.ocs_add_low + translit.ocs_add_upp - if mode == "iso9_ocs_hack" then + if translit.deficient_font == "yes" then cyr = cyr + translit.ru_jer_hack end @@ -248,11 +250,36 @@ local function scientific (mode, text) scientific_parser = Cs((p_cyr / cyr + utfchar)^0) end - return scientific_parser:match(text) + return scientific_parser end -translit.methods ["iso9_ocs"] = function (text) return scientific( "iso9_ocs" , text ) end -translit.methods ["iso9_ocs_hack"] = function (text) return scientific( "iso9_ocs_hack", text ) end -translit.methods ["ocs"] = function (text) return scientific( "ocs" , text ) end -translit.methods ["ocs_gla"] = function (text) return scientific( "ocs_gla" , text ) end +translit.methods["iso9_ocs"] = function (text) + local pname = "iso9_ocs" .. translit.deficient_font + local p = pcache[pname] + if not p then + p = scientific("iso9_ocs") + pcache[pname] = p + end + return lpegmatch(p, text) +end + +translit.methods["ocs"] = function (text) + local p = pcache["ocs"] + if not p then + p = scientific("ocs") + pcache["ocs"] = p + end + return lpegmatch(p, text) +end + +translit.methods["ocs_gla"] = function (text) + local p = pcache["ocs_gla"] + if not p then + p = scientific("ocs_gla") + pcache["ocs_gla"] = p + end + return lpegmatch(p, text) +end + +-- vim:ft=lua:ts=4:sw=4 -- cgit v1.2.3