Pre-expand tables on SETLIST
This commit is contained in:
@@ -568,6 +568,11 @@ public class LTable extends LValue {
|
|||||||
array = v;
|
array = v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void arrayPresize(int minSize) {
|
||||||
|
if ( array.length < minSize )
|
||||||
|
arrayExpand(minSize);
|
||||||
|
}
|
||||||
|
|
||||||
// ============= Hashtable ================
|
// ============= Hashtable ================
|
||||||
|
|
||||||
public void hashSet(LValue key, Object value) {
|
public void hashSet(LValue key, Object value) {
|
||||||
|
|||||||
@@ -824,6 +824,7 @@ public class LuaState extends Lua {
|
|||||||
}
|
}
|
||||||
int offset = (c-1) * LFIELDS_PER_FLUSH;
|
int offset = (c-1) * LFIELDS_PER_FLUSH;
|
||||||
LTable tbl = (LTable) this.stack[base + a];
|
LTable tbl = (LTable) this.stack[base + a];
|
||||||
|
tbl.arrayPresize( offset + b );
|
||||||
for (int j=1; j<=b; j++) {
|
for (int j=1; j<=b; j++) {
|
||||||
tbl.put(offset+j, stack[listBase + j]);
|
tbl.put(offset+j, stack[listBase + j]);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -142,3 +142,21 @@ t[6] = 'six'
|
|||||||
testbothpairs(t)
|
testbothpairs(t)
|
||||||
t[4] = nil
|
t[4] = nil
|
||||||
testbothpairs(t)
|
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)}))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user