lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

> My point was mostly that if the performance is a concern, then the place to
> fix this is not by changing the lexer but to introduce constant folding into
> the compiler for this operation.

I think Roberto's point is that constant folding wouldn't save you anything in
the common case (where the concatenation is not in a loop). The compiler would
still generate N-2 intermediate strings, it would just do it during code
generation rather than execution (both happen at runtime in Lua).

If it could be done while lexing, it would be *far* more efficient. It's no
more expensive to lex fifty 10-character strings than one 500-character string
(you're just skipping unwanted characters); the parser/code generator sees only
1 string, no concatenation required, no intermediates allocated.