diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-07-15 14:59:35 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-07-15 14:59:35 -0300 |
| commit | 758c1ef445ab27d89bace746111add04083a8e20 (patch) | |
| tree | 8136726cfaa1dc0841547987f2cb0555d02f2303 /lvm.c | |
| parent | dd6d8db49acda5d5353a0a9c42485d9b4bde419d (diff) | |
| download | lua-758c1ef445ab27d89bace746111add04083a8e20.tar.gz lua-758c1ef445ab27d89bace746111add04083a8e20.tar.bz2 lua-758c1ef445ab27d89bace746111add04083a8e20.zip | |
Unification of size representation in OP_NEWTABLE and OP_SETLIST
Opcodes OP_NEWTABLE and OP_SETLIST use the same representation to
store the size of the array part of a table. This new representation
can go up to 2^33 (8 + 25 bits).
Diffstat (limited to 'lvm.c')
| -rw-r--r-- | lvm.c | 28 |
1 files changed, 14 insertions, 14 deletions
| @@ -1247,18 +1247,19 @@ void luaV_execute (lua_State *L, CallInfo *ci) { | |||
| 1247 | vmbreak; | 1247 | vmbreak; |
| 1248 | } | 1248 | } |
| 1249 | vmcase(OP_NEWTABLE) { | 1249 | vmcase(OP_NEWTABLE) { |
| 1250 | int b = GETARG_B(i); | 1250 | int b = GETARG_B(i); /* log2(hash size) + 1 */ |
| 1251 | int c = GETARG_C(i); | 1251 | int c = GETARG_C(i); /* array size */ |
| 1252 | Table *t; | 1252 | Table *t; |
| 1253 | c = (c == 0) ? 0 : 1 << (c - 1); /* size is 2^c */ | 1253 | if (b > 0) |
| 1254 | if (b >= LIMTABSZ) | 1254 | b = 1 << (b - 1); /* size is 2^(b - 1) */ |
| 1255 | b += LFIELDS_PER_FLUSH * GETARG_Ax(*pc) - LIMTABSZ; | 1255 | if (TESTARG_k(i)) |
| 1256 | c += GETARG_Ax(*pc) * (MAXARG_C + 1); | ||
| 1256 | pc++; /* skip extra argument */ | 1257 | pc++; /* skip extra argument */ |
| 1257 | L->top = ci->top; /* correct top in case of GC */ | 1258 | L->top = ci->top; /* correct top in case of GC */ |
| 1258 | t = luaH_new(L); /* memory allocation */ | 1259 | t = luaH_new(L); /* memory allocation */ |
| 1259 | sethvalue2s(L, ra, t); | 1260 | sethvalue2s(L, ra, t); |
| 1260 | if (b != 0 || c != 0) | 1261 | if (b != 0 || c != 0) |
| 1261 | luaH_resize(L, t, b, c); /* idem */ | 1262 | luaH_resize(L, t, c, b); /* idem */ |
| 1262 | checkGC(L, ra + 1); | 1263 | checkGC(L, ra + 1); |
| 1263 | vmbreak; | 1264 | vmbreak; |
| 1264 | } | 1265 | } |
| @@ -1763,18 +1764,17 @@ void luaV_execute (lua_State *L, CallInfo *ci) { | |||
| 1763 | } | 1764 | } |
| 1764 | vmcase(OP_SETLIST) { | 1765 | vmcase(OP_SETLIST) { |
| 1765 | int n = GETARG_B(i); | 1766 | int n = GETARG_B(i); |
| 1766 | int c = GETARG_C(i); | 1767 | unsigned int last = GETARG_C(i); |
| 1767 | unsigned int last; | 1768 | Table *h = hvalue(s2v(ra)); |
| 1768 | Table *h; | ||
| 1769 | if (n == 0) | 1769 | if (n == 0) |
| 1770 | n = cast_int(L->top - ra) - 1; | 1770 | n = cast_int(L->top - ra) - 1; /* get up to the top */ |
| 1771 | else | 1771 | else |
| 1772 | L->top = ci->top; /* correct top in case of GC */ | 1772 | L->top = ci->top; /* correct top in case of GC */ |
| 1773 | if (c == 0) { | 1773 | last += n; |
| 1774 | c = GETARG_Ax(*pc); pc++; | 1774 | if (TESTARG_k(i)) { |
| 1775 | last += GETARG_Ax(*pc) * (MAXARG_C + 1); | ||
| 1776 | pc++; | ||
| 1775 | } | 1777 | } |
| 1776 | h = hvalue(s2v(ra)); | ||
| 1777 | last = ((c-1)*LFIELDS_PER_FLUSH) + n; | ||
| 1778 | if (last > luaH_realasize(h)) /* needs more space? */ | 1778 | if (last > luaH_realasize(h)) /* needs more space? */ |
| 1779 | luaH_resizearray(L, h, last); /* preallocate it at once */ | 1779 | luaH_resizearray(L, h, last); /* preallocate it at once */ |
| 1780 | for (; n > 0; n--) { | 1780 | for (; n > 0; n--) { |
