[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Alternative string concat (was "out of memory ")
- From: Luiz Henrique de Figueiredo <lhf@...>
- Date: Mon, 7 Oct 2002 17:37:16 -0300 (EST)
>Since the speed of the string .. operation is slow (a problem shared by
>several languages) you could fix the problem by increasing the speed of
>the existing .. operation or you could use some other, faster technique.
The string .. operation is not slow in Lua. It's actually very fast, even
for multiple concatenations. The virtual machine operation is actually for
multiple concatenation. Here is the code for
return "a" .."b" .."c" .."d"
1 [2] LOADK 0 0 ; "a"
2 [2] LOADK 1 1 ; "b"
3 [2] LOADK 2 2 ; "c"
4 [2] LOADK 3 3 ; "d"
5 [2] CONCAT 0 0 3
So, this is a linear (not quadratic) operation.
Bottom line: there's no reason not to use multiple concatenations for long
strings. (Except that there is a limit on the number of concatenations.)
--lhf