I have two strings. One of them is often (but not always) empty. The other is huge:
a = ""
b = "... huge string ..."
I need to concatenate the two strings. So I do the following:
return a .. b
But, if a
is empty, this would, temporarily, unnecessarily create a copy of the huge string.
So I thought to write it as follows:
return (a == "" and b) or (a .. b)
This would solve the problem. But, I was wondering: does Lua optimize a concatenation that involves an empty string? That is, if we write a .. b
, does Lua check to see if either of the strings is empty and return the other one immediately? If so, I could simply write a ..b
instead of the more elaborate code.