diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2006-09-25 12:35:00 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2006-09-25 12:35:00 -0300 |
commit | 285f926140bcc3155d3d7a9d03ced55b1e2bc0f5 (patch) | |
tree | 32e149111ad11c21dbcb24f9273eca098d6f907a | |
parent | 3c8865cf66db165e0266b642a1fdcff6c72a9e24 (diff) | |
download | lua-285f926140bcc3155d3d7a9d03ced55b1e2bc0f5.tar.gz lua-285f926140bcc3155d3d7a9d03ced55b1e2bc0f5.tar.bz2 lua-285f926140bcc3155d3d7a9d03ced55b1e2bc0f5.zip |
avoid using index 0 for free list of references (because it is not
as efficient as index 1...)
-rw-r--r-- | lauxlib.c | 10 |
1 files changed, 8 insertions, 2 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lauxlib.c,v 1.161 2006/09/18 14:03:18 roberto Exp roberto $ | 2 | ** $Id: lauxlib.c,v 1.162 2006/09/22 20:24:38 roberto Exp roberto $ |
3 | ** Auxiliary functions for building Lua libraries | 3 | ** Auxiliary functions for building Lua libraries |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -25,7 +25,11 @@ | |||
25 | #include "lauxlib.h" | 25 | #include "lauxlib.h" |
26 | 26 | ||
27 | 27 | ||
28 | #define FREELIST_REF 0 /* free list of references */ | 28 | /* number of prereserved references (for internal use) */ |
29 | #define RESERVED_REFS 1 /* only FREELIST_REF is reserved */ | ||
30 | |||
31 | #define FREELIST_REF 1 /* free list of references */ | ||
32 | |||
29 | 33 | ||
30 | 34 | ||
31 | /* convert a stack index to positive */ | 35 | /* convert a stack index to positive */ |
@@ -494,6 +498,8 @@ LUALIB_API int luaL_ref (lua_State *L, int t) { | |||
494 | } | 498 | } |
495 | else { /* no free elements */ | 499 | else { /* no free elements */ |
496 | ref = (int)lua_objlen(L, t); | 500 | ref = (int)lua_objlen(L, t); |
501 | if (ref < RESERVED_REFS) | ||
502 | ref = RESERVED_REFS; /* skip reserved references */ | ||
497 | ref++; /* create new reference */ | 503 | ref++; /* create new reference */ |
498 | } | 504 | } |
499 | lua_rawseti(L, t, ref); | 505 | lua_rawseti(L, t, ref); |