|
Am 28.03.2018 um 18:04 schröbte Petri Häkkinen:
The differences with arrays emulated with tables are: + much, much higher performance than possible with ’n’ field trick + standardized way to query the length (using the # operator) + the length is automatically updated when you insert values — this is essentially for free
Couldn't you just add the length-updating code to normal tables? I mean we already pay the extra space for the length field. Then we wouldn't need a table subtype or new syntax, and the following code would continue to work as expected:
function tcopy( t ) local copy = {} for k,v in pairs( t ) do copy[ k ] = v end return copy -- returns an array if given an array end
Petri
Philippp.s. I believe this proposal isn't new and was rejected because of the extra space and performance cost for non-array tables, but maybe your benchmarks change that.