summaryrefslogtreecommitdiff
path: root/tex/context/base/node-nut.lua
diff options
context:
space:
mode:
authorContext Git Mirror Bot <phg42.2a@gmail.com>2015-09-01 11:15:08 +0200
committerContext Git Mirror Bot <phg42.2a@gmail.com>2015-09-01 11:15:08 +0200
commitf4508b5b95b4fc2b3ed59aaa28a8dfc1a667360a (patch)
tree74d5ca2ad226b4b8fa07c512f433c11b7b9acaaf /tex/context/base/node-nut.lua
parentdb76d739a1e8dc1faa0ba194d4d4f2d6081e9ae7 (diff)
downloadcontext-f4508b5b95b4fc2b3ed59aaa28a8dfc1a667360a.tar.gz
2015-09-01 11:12:00
Diffstat (limited to 'tex/context/base/node-nut.lua')
-rw-r--r--tex/context/base/node-nut.lua103
1 files changed, 103 insertions, 0 deletions
diff --git a/tex/context/base/node-nut.lua b/tex/context/base/node-nut.lua
index 554d74ec5..de03fd433 100644
--- a/tex/context/base/node-nut.lua
+++ b/tex/context/base/node-nut.lua
@@ -240,6 +240,109 @@ if not direct.mlist_to_hlist then
end
+-- new, a few experimental extra helpers that can speed up font handling 15%
+-- especially a mix of complex (latin) features and discretionaries or complex
+-- scripts with lots of contextual chains (for other use there is not that
+-- much gain)
+
+if not direct.getdisc then
+
+ local getid = nuts.getid
+ local getsubtype = nuts.getsubtype
+ local getfont = nuts.getfont
+ local getfield = nuts.getfield
+ local setfield = nuts.setfield
+ local findtail = nuts.tail
+
+ local glyph_code = nodecodes.glyph
+
+ -- this one saves finding tails (i.e. extra calls and passes)
+
+ function direct.getdisc(n,tailtoo)
+ local pre = getfield(n,"pre")
+ local post = getfield(n,"post")
+ local replace = getfield(n,"replace")
+ if tailtoo then
+ return pre, post, replace,
+ pre and findtail(pre),
+ post and findtail(post),
+ replace and findtail(replace)
+
+ else
+ return pre, post, replace
+ end
+ end
+
+ -- this one is more efficient than three assignments and we need to
+ -- do it in order to updat ethe internal tail data (will change)
+
+ function direct.setdisc(n,pre,post,replace,subtype)
+ setfield(n,"pre",pre)
+ setfield(n,"post",post)
+ setfield(n,"replace",replace)
+ if subtype then
+ setfield(n,"subtype",subtype)
+ end
+ end
+
+ -- very small speedup but more convenient
+
+ function direct.setchar(n,chr)
+ setfield(n,"char",chr)
+ end
+
+ function direct.setnext(n,next)
+ setfield(n,"next",next)
+ end
+
+ function direct.setprev(g,prev)
+ setfield(n,"prev",prev)
+ end
+
+ function direct.setboth(n,prev,next)
+ if n then
+ setfield(n,"next",next)
+ setfield(n,"prev",prev)
+ end
+ end
+
+ function direct.getboth(n)
+ if n then
+ return getfield(n,"prev"), getfield(n,"prev")
+ end
+ end
+
+ function direct.setlink(a,b)
+ if a then
+ if b then
+ setfield(a,"next",b)
+ setfield(b,"prev",a)
+ else
+ setfield(a,"next",nil)
+ end
+ elseif b then
+ setfield(b,"prev",nil)
+ end
+ end
+
+ -- this one saves a lot (one call instead of 3)
+
+ function direct.is_char(g,font)
+ return getid(g) == glyph_code and getsubtype(g) < 256 and (not font or getfont(g) == font)
+ end
+
+end
+
+nuts.getdisc = direct.getdisc
+nuts.setdisc = direct.setdisc
+nuts.setchar = direct.setchar
+nuts.setnext = direct.setnext
+nuts.setprev = direct.setprev
+nuts.setboth = direct.setboth
+nuts.getboth = direct.getboth
+nuts.setlink = direct.setlink
+nuts.is_char = direct.is_char
+
--
local d_remove_node = direct.remove