lua-users home
lua-l archive

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


On 25 August 2015 at 16:36, Ulrich Schmidt <u.sch.zw@gmx.de> wrote:
> Hi all.
>
> I deal with some really large strings i have to sort in some way and finally
> create a concatinated result string. The string content doesnt change.
> I store the strings in a table using non integer keys. (eg.: file names)
> I dont want to make copies of the strings because they are large.
> Finally i create a sorted table with integer keys and do a table.concat to
> create the
> really large result string.
>
> Now the problem:
>
> i want to move a string without making a copy
> from a table '[string] = string"' to a table '[int] = string'.
>
> table.remove() doesnt work because it requests integer keys.
>
> So i do a simple asignment;
>     td[int] = ts["key"];
>     ts["key"] = nil;
>
> As far as i know this creates a copy of the value-sting.

It does not. It creates a 2nd reference to the same string.

> My question/ suggestion:
>
> Why not allow string keys in table.remove?
> Simply remove one entry from the table without shifting around other
> entries.
>
> Any pros and cons? I overlooked something?

table.remove is not what you want here.