Pre-expand tables on SETLIST

This commit is contained in:
James Roseborough
2008-07-23 14:07:25 +00:00
parent 887658ae7b
commit a217f8a202
3 changed files with 24 additions and 0 deletions

View File

@@ -568,6 +568,11 @@ public class LTable extends LValue {
array = v;
}
public void arrayPresize(int minSize) {
if ( array.length < minSize )
arrayExpand(minSize);
}
// ============= Hashtable ================
public void hashSet(LValue key, Object value) {

View File

@@ -824,6 +824,7 @@ public class LuaState extends Lua {
}
int offset = (c-1) * LFIELDS_PER_FLUSH;
LTable tbl = (LTable) this.stack[base + a];
tbl.arrayPresize( offset + b );
for (int j=1; j<=b; j++) {
tbl.put(offset+j, stack[listBase + j]);
}

View File

@@ -142,3 +142,21 @@ t[6] = 'six'
testbothpairs(t)
t[4] = nil
testbothpairs(t)
-- tests of setlist table constructors
local function a(...) return ... end
print('-',unpack({a()}))
print('a',unpack({a('a')}))
print('.',unpack({a(nil)}))
print('ab',unpack({a('a', 'b')}))
print('.b',unpack({a(nil, 'a')}))
print('a.',unpack({a('a', nil)}))
print('abc',unpack({a('a', 'b', 'c')}))
print('.ab',unpack({a(nil, 'a', 'b')}))
print('a.b',unpack({a('a', nil, 'b')}))
print('ab.',unpack({a('a', 'b', nil)}))
print('..b',unpack({a(nil, nil, 'b')}))
print('a..',unpack({a('a', nil, nil)}))
print('.b.',unpack({a(nil, 'b', nil)}))
print('...',unpack({a(nil, nil, nil)}))