lua-users home
lua-l archive

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



On Jul 31, 2014 8:50 PM, "Tim Hill" <drtimhill@gmail.com> wrote:
>
>
> On Jul 31, 2014, at 12:42 PM, Andrew Starks <andrew.starks@trms.com> wrote:

> > I also agree that "table.copy" seems to suggest "any key value". Obviously its definition clears that up. "table.icopy" seems to fit "pairs" and "ipairs", but I don't mean to nitpick.
>
> +1 for table.icopy().

If I had to choose between the two names, I would choose icopy for sure.

Microlight uses the term "extend" for array-like append and "update" for map-like overwrite.

https://github.com/stevedonovan/Microlight/blob/master/readme.md#inserting-and-extending

These take a variable number of arguments. If you want a fresh table, just add {} as the first argument.

update(t, {k="v"})
t2 = update({}, t, {k2="v2"})

> > It was mentioned that "table.clear" (or similar) was likely. Was it decided that it would not be useful?
>
> My guess here is that there is no real performance gain.

Is that true for operations on scalars in the array part?

> There are a number of tricks table.copy() can do to optimize the copy that can’t really be coded in Lua (not saying it DOES these, just that it COULD), while a clear function in Lua is pretty much as good as a C version.

If update/extend were implemented in C, they might see a performance gain if the C code were in charge of creating the fresh table, since C code can look under the covers of the arguments.

Jay