Suppose I have the following loop:
for name in poll() do
if name == "quit" then
return 0
end
end
Will the "quit" string be re-created and cleaned up with every iteration, or will Lua re-use the same instance?
Suppose I have the following loop:
for name in poll() do
if name == "quit" then
return 0
end
end
Will the "quit" string be re-created and cleaned up with every iteration, or will Lua re-use the same instance?
It is just created one time and then it is "internalized", that it is saved in a hash table and then reused.
From The Implementation of Lua 5.0
Lua internalizes strings using a hash table: it keeps a single copy of each string with no duplications.