[Dev-luatex] getnext et al.

Hans Hagen pragma at wxs.nl
Tue May 6 10:02:40 CEST 2014


On 5/6/2014 7:39 AM, Philipp Gesang wrote:
> Hi Patrick!
>
> ···<Datum: Saturday, 03. May 2014>···<Von: Patrick Gundlach>···
>
>> Hi,
>>
>> reading the chapter 8.2 in the manual, I wonder how to call getnext and its ilk. Is this used like node.getnext()?
>
> Yes, but they operate on integer references which you obtain by
> calling node.direct.todirect() on the node you start out with:

     local l = tex.getbox(0).list
     print(node.getnext(l),node.direct.getnext(node.direct.todirect(l)))

so, node.getnext(n) works on 'normal nodes' (and can be faster than 
n.next as it saves a metatable lookup + some internal speedup) ... if 
it's really faster depends on the the use case (and using it also 
relates to readability ... often n.next looks nicer)

never think of direct nodes as integers .. they're abstractions that 
happen to be (positive) numbers

>      local direct            = node.direct
>      local getnext           = direct.getnext
>      local todirect          = direct.todirect
>      local getid             = direct.getid
>      local getfield          = direct.getfield
>      local setfield          = direct.setfield
>
>      local glyph_node        = node.id "glyph"
>      local asciiA, asciia    = string.byte "A", string.byte "a"
>
>      local r13 = function (chr)
>        local d
>        d = chr - asciiA if 0 <= d and d <= 25 then return (d + 13) % 26 + asciiA end
>        d = chr - asciia if 0 <= d and d <= 25 then return (d + 13) % 26 + asciia end
>        return chr
>      end
>
>      local filter = function (hd)
>        local cur = todirect (hd)                     ---> node -> int
>        while cur do
>          if getid (cur) == glyph_node then           ---> if cur.id == glyph_node
>            local chr = getfield (cur, "char")        ---> chr = cur.char
>            setfield (cur, "char", r13 (chr))         ---> cur.char = r13 (cur.char)
>          end
>          cur = getnext (cur)                         ---> cur = cur.next
>        end
>        return hd                                     ---> return first node
>      end
>
>      callback.register ("pre_linebreak_filter", filter)
>
> To my knowledge, the correspondence between the functions under
> node.* and node.direct.* is most obvious in node-nut.lua:
>
>      http://git.contextgarden.net/context/context/blob/master/tex/context/base/node-nut.lua

it's called nut for a reason -)

> @Hans: Considering that node.direct has been part of the master
> branch for some time and the new model is used in Context without
> users reporting segfaults, could you give an ETA on when the
> generic fontloader will benefit from it?

hard to say ... keep in mind that the gain is mostly in complex font 
handling of manipulations and that is not always that generic (

btw, there are some more changes in the font related code (on my 
machine, one of these days in the core ... given some testing by others) 
... one reason for keeping this separate from generic is that i don't 
want to break that (esp not around tex live code freeze)

the latest generic code + the latest luatex already should run somewhat 
faster (something halfway) as the regular node code was also optimized

version                           fonts about arabic

old indexed plus some functions   8.9   3.2   20.3
old fake functions                9.9   3.5   27.4

new node functions                9.0   3.1   20.8
new indexed plus some functions   8.6   3.1   19.6
new direct functions              7.5   2.6   14.4

[from the "going nuts" article]

the arabic test was using an extreme font and only doing text (in normal 
document font handling time can disappear in the rest), the about 
document was a lot of math, and the 160 page fonts document uses quite 
some fonts and features

(of course it does make a difference in fully automated workflows on a 
loaded server where one needs to generate sets of 5 documents (times n 
runs) and/or documents with 2000 pages and where a user is waiting)

Hans

-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
     tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com
                                              | www.pragma-pod.nl
-----------------------------------------------------------------


More information about the dev-luatex mailing list