[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Ideas about implementing a string type?
- From: Rici Lake <lua@...>
- Date: Sun, 01 Apr 2007 17:08:29 -0500
One has to use an idiom like var->ptr[i++] instead of *p++ across
calls. In comparison to the cost of the call, the price in
performance should be negligible. There is an impact in readability,
but then using pointers instead of indexing is arguably not always an
improvement in legibility, either.
That's fine if the function is using the string itself (which is
probably the majority case, but certainly not always). In some
cases, it would require copying the string value in order to
guarantee pointer safety, though. (Consider asynchronous output
via a workqueue.)
In any event, there is a lot of Lua extension code already written
which would need extensive rewriting against that model, including
most or all of the Lua extensions used by LuaTeX. So it's not a
change that could be made lightly.
There is another option _if_ one decides to make every string (and not
just specific lightweight/uninterned strings) hold its content address
and does not guarantee its constancy over its life time: this could
allow for compacting garbage collection of string space.
Unfortunately, even if strings were relocatable, userdata would not be.
It's conceivable that compacting would be useful even if userdata
were excluded, though. It would make for an interesting experiment.