aboutsummaryrefslogtreecommitdiff
path: root/lcode.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2013-08-30 13:01:37 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2013-08-30 13:01:37 -0300
commit8ef9e8460e775793f760deb28d0c3d10dda31b49 (patch)
tree803abce8b7caba6e5f66b26e55f0bc8dcfc881a2 /lcode.c
parent4f292d753c892e705b6d1796d72758cdd4d49765 (diff)
downloadlua-8ef9e8460e775793f760deb28d0c3d10dda31b49.tar.gz
lua-8ef9e8460e775793f760deb28d0c3d10dda31b49.tar.bz2
lua-8ef9e8460e775793f760deb28d0c3d10dda31b49.zip
bug (GC can collect long identifier during parser) + change (using
a single constant table for all functions in a chunk)
Diffstat (limited to 'lcode.c')
-rw-r--r--lcode.c20
1 files changed, 12 insertions, 8 deletions
diff --git a/lcode.c b/lcode.c
index 7a9cb6fb..4dd823f2 100644
--- a/lcode.c
+++ b/lcode.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lcode.c,v 2.70 2013/06/20 17:37:31 roberto Exp roberto $ 2** $Id: lcode.c,v 2.71 2013/06/25 18:57:18 roberto Exp roberto $
3** Code generator for Lua 3** Code generator for Lua
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -307,17 +307,21 @@ static void freeexp (FuncState *fs, expdesc *e) {
307} 307}
308 308
309 309
310/*
311** Use scanner's table to cache position of constants in contant list
312** and try to reuse constants
313*/
310static int addk (FuncState *fs, TValue *key, TValue *v) { 314static int addk (FuncState *fs, TValue *key, TValue *v) {
311 lua_State *L = fs->ls->L; 315 lua_State *L = fs->ls->L;
312 TValue *idx = luaH_set(L, fs->h, key);
313 Proto *f = fs->f; 316 Proto *f = fs->f;
317 TValue *idx = luaH_set(L, fs->ls->h, key); /* index scanner table */
314 int k, oldsize; 318 int k, oldsize;
315 if (ttisinteger(idx)) { 319 if (ttisinteger(idx)) { /* is there an index there? */
316 k = ivalue(idx); 320 k = ivalue(idx);
317 if (luaV_rawequalobj(&f->k[k], v)) 321 /* correct value? (warning: must distinguish floats from integers!) */
318 return k; 322 if (k < fs->nk && ttype(&f->k[k]) == ttype(v) &&
319 /* else may be a collision (e.g., between 0.0 and "\0\0\0\0\0\0\0\0"); 323 luaV_rawequalobj(&f->k[k], v))
320 go through and create a new entry for this value */ 324 return k; /* reuse index */
321 } 325 }
322 /* constant not found; create a new entry */ 326 /* constant not found; create a new entry */
323 oldsize = f->sizek; 327 oldsize = f->sizek;
@@ -377,7 +381,7 @@ static int nilK (FuncState *fs) {
377 TValue k, v; 381 TValue k, v;
378 setnilvalue(&v); 382 setnilvalue(&v);
379 /* cannot use nil as key; instead use table itself to represent nil */ 383 /* cannot use nil as key; instead use table itself to represent nil */
380 sethvalue(fs->ls->L, &k, fs->h); 384 sethvalue(fs->ls->L, &k, fs->ls->h);
381 return addk(fs, &k, &v); 385 return addk(fs, &k, &v);
382} 386}
383 387