[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: string immutability
- From: Steve Litt <slitt@...>
- Date: Thu, 2 Jan 2014 12:49:47 -0500
On Thu, 2 Jan 2014 12:54:02 +0000
Thijs Schreijer <thijs@thijsschreijer.nl> wrote:
> I don't know how it works in practice, but what you're suggesting
> means that after each string operation the resulting string would
> have to be compared to every other string in the current Lua state...
> I doubt whether that would be possible performance wise.
>
> Considering the example again:
> local first = [[ some 100mb stuff here ]]
> local second = first
> local third = first .. "" -- changed here, result is the same
Regardless of interning, just do this:
if string_to_append ~= ""
newstring = oldstring .. string_to_append
else
newstring = oldstring
The preceding does the right thing in every case. I'm almost positive
that you can reassign strings all over the place, and you have just one
copy of the data. I *know* I've used that to my advantage on tables,
and I think it works on strings.
But your best bet is simply make a little test program to find out for
sure.
SteveT
Steve Litt * http://www.troubleshooters.com/
Troubleshooting Training * Human Performance