[luatex] Copy or recreate nodes.

Taco Hoekwater taco at elvenkind.com
Sat Aug 7 10:55:50 CEST 2010


Hi Paul,

On 08/06/2010 08:02 PM, Paul Isambert wrote:
> Hello all,
>
> It's a bit calm here today, so let's ask a somewhat Byzantine question so we (at
> least I) will be a little more knowledgeable tonight.
>
> Suppose I want to add a node in a list. The question is, what's the preferred
> solution between the following two:
>
> 1. Create one node and copy it:
> \directlua{%
>    mynode = node.create(10) % Let's say it's a glue.
>    % Some node specs here
>    function addnode (head,place)
>      node.insert_after(head,place,node.copy(mynode))
>    end
>    }
>
> 2. Create a new node each time:
> \directlua{%
>    function addnode(head,place)
>      local mynode = node.create(10)
>      % Some node specs here
>      node.insert_after(head,place,mynode)
>    end
>    }
>
> Both approaches work, but: is one better/faster/more economical than the other?

The first solution is somewhat faster (fewer function calls), but
whether it is 'better' depends on the 'Some node specs': if all nodes
are the same, the first solution is a bit cleaner to look at as well
so then I would use that. But if there are even slight variations, the
second form makes this more obvious, and I would use that. The speed
gain is not that much.

There are not *that* many nodes involved with typesetting, so unless
you do lots and lots of work, you won't notice any difference.

Best wishes,
Taco





More information about the luatex mailing list