picky question about length operator
Posted: Wed Dec 03, 2008 8:10 pm
I've been using the length operator (#) lots these days, since the thread here which showed it was much faster than table.maxn.
However, I've begun using structures which have both tightly-packed enumerated data, and data with string keys. For example:
test = {
x = 0,
y = 0,
name = "Funny Table",
}
for i=1, 100 do
test = i
end
this table would then have 103 pieces of data.
I often want to iterate through the numericly indexed elements of the table, which I could do with i=1, table.maxn(test). The function table.maxn is very clearly "The highest order numerical index" while the description of the length operator is a bit less clear.
Both appear to be working, but the length operator has several warnings about calling it. I can't quite make up my mind whether or not I should be safe and sacrifice some performance now. Anyone have any insight?
--Mr. Strange
However, I've begun using structures which have both tightly-packed enumerated data, and data with string keys. For example:
test = {
x = 0,
y = 0,
name = "Funny Table",
}
for i=1, 100 do
test = i
end
this table would then have 103 pieces of data.
I often want to iterate through the numericly indexed elements of the table, which I could do with i=1, table.maxn(test). The function table.maxn is very clearly "The highest order numerical index" while the description of the length operator is a bit less clear.
Both appear to be working, but the length operator has several warnings about calling it. I can't quite make up my mind whether or not I should be safe and sacrifice some performance now. Anyone have any insight?
--Mr. Strange