commit 285f926140bcc3155d3d7a9d03ced55b1e2bc0f5
parent 3c8865cf66db165e0266b642a1fdcff6c72a9e24
Author: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Date: Mon, 25 Sep 2006 12:34:37 -0300
avoid using index 0 for free list of references (because it is not
as efficient as index 1...)
Diffstat:
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/lauxlib.c b/lauxlib.c
@@ -1,5 +1,5 @@
/*
-** $Id: lauxlib.c,v 1.161 2006/09/18 14:03:18 roberto Exp roberto $
+** $Id: lauxlib.c,v 1.162 2006/09/22 20:24:38 roberto Exp roberto $
** Auxiliary functions for building Lua libraries
** See Copyright Notice in lua.h
*/
@@ -25,7 +25,11 @@
#include "lauxlib.h"
-#define FREELIST_REF 0 /* free list of references */
+/* number of prereserved references (for internal use) */
+#define RESERVED_REFS 1 /* only FREELIST_REF is reserved */
+
+#define FREELIST_REF 1 /* free list of references */
+
/* convert a stack index to positive */
@@ -494,6 +498,8 @@ LUALIB_API int luaL_ref (lua_State *L, int t) {
}
else { /* no free elements */
ref = (int)lua_objlen(L, t);
+ if (ref < RESERVED_REFS)
+ ref = RESERVED_REFS; /* skip reserved references */
ref++; /* create new reference */
}
lua_rawseti(L, t, ref);