commit 572a69df78b2636642e9c520ebc8c1d2efa16afe
parent 943c82b37622bd2321d4fbb361d99f4495ceed2f
Author: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Date: Mon, 28 Apr 2003 16:25:54 -0300
Lua does not need all those different types...
Diffstat:
6 files changed, 32 insertions(+), 26 deletions(-)
diff --git a/lgc.c b/lgc.c
@@ -1,5 +1,5 @@
/*
-** $Id: lgc.c,v 1.170 2003/03/18 12:50:04 roberto Exp roberto $
+** $Id: lgc.c,v 1.171 2003/04/03 13:35:34 roberto Exp roberto $
** Garbage Collector
** See Copyright Notice in lua.h
*/
@@ -389,7 +389,7 @@ static void sweepstrings (lua_State *L, int all) {
static void checkSizes (lua_State *L) {
/* check size of string hash */
- if (G(L)->strt.nuse < cast(ls_nstr, G(L)->strt.size/4) &&
+ if (G(L)->strt.nuse < cast(lu_int32, G(L)->strt.size/4) &&
G(L)->strt.size > MINSTRTABSIZE*2)
luaS_resize(L, G(L)->strt.size/2); /* table is too big */
/* check size of buffer */
diff --git a/llimits.h b/llimits.h
@@ -1,5 +1,5 @@
/*
-** $Id: llimits.h,v 1.51 2002/11/25 17:47:13 roberto Exp roberto $
+** $Id: llimits.h,v 1.52 2003/02/20 19:33:23 roberto Exp roberto $
** Limits, basic types, and some other `installation-dependent' definitions
** See Copyright Notice in lua.h
*/
@@ -40,20 +40,25 @@
** any machine, but may not be optimal.
*/
-/* an unsigned integer to hold hash values */
-typedef unsigned int lu_hash;
-/* its signed equivalent */
-typedef int ls_hash;
-/* an unsigned integer big enough to count the total memory used by Lua; */
-/* it should be at least as large as size_t */
-typedef unsigned long lu_mem;
+/*
+** an unsigned integer with at least 32 bits
+*/
+#ifndef LUA_UINT32
+#define LUA_UINT32 unsigned long
+#endif
+
+typedef LUA_UINT32 lu_int32;
-#define MAX_LUMEM ULONG_MAX
+/*
+** an unsigned integer big enough to count the total memory used by Lua;
+** it should be at least as large as `size_t'
+*/
+typedef lu_int32 lu_mem;
+
+#define MAX_LUMEM ULONG_MAX
-/* an integer big enough to count the number of strings in use */
-typedef long ls_nstr;
/* chars used as small naturals (so that `char' is reserved for characters) */
typedef unsigned char lu_byte;
@@ -69,7 +74,7 @@ typedef unsigned char lu_byte;
** this is for hashing only; there is no problem if the integer
** cannot hold the whole pointer value
*/
-#define IntPoint(p) ((lu_hash)(p))
+#define IntPoint(p) ((unsigned int)(p))
@@ -114,7 +119,7 @@ typedef LUA_UACNUMBER l_uacNumber;
** type for virtual-machine instructions
** must be an unsigned with (at least) 4 bytes (see details in lopcodes.h)
*/
-typedef unsigned long Instruction;
+typedef lu_int32 Instruction;
/* maximum depth for calls (unsigned short) */
diff --git a/lobject.h b/lobject.h
@@ -1,5 +1,5 @@
/*
-** $Id: lobject.h,v 1.158 2003/02/18 16:02:56 roberto Exp roberto $
+** $Id: lobject.h,v 1.159 2003/03/18 12:50:04 roberto Exp roberto $
** Type definitions for Lua objects
** See Copyright Notice in lua.h
*/
@@ -181,7 +181,7 @@ typedef union TString {
struct {
CommonHeader;
lu_byte reserved;
- lu_hash hash;
+ unsigned int hash;
size_t len;
} tsv;
} TString;
diff --git a/lstate.h b/lstate.h
@@ -1,5 +1,5 @@
/*
-** $Id: lstate.h,v 1.108 2002/11/25 17:47:13 roberto Exp roberto $
+** $Id: lstate.h,v 1.109 2003/02/27 11:52:30 roberto Exp roberto $
** Global State
** See Copyright Notice in lua.h
*/
@@ -64,7 +64,7 @@ struct lua_longjmp; /* defined in ldo.c */
typedef struct stringtable {
GCObject **hash;
- ls_nstr nuse; /* number of elements */
+ lu_int32 nuse; /* number of elements */
int size;
} stringtable;
diff --git a/lstring.c b/lstring.c
@@ -1,5 +1,5 @@
/*
-** $Id: lstring.c,v 1.77 2002/11/13 11:32:26 roberto Exp roberto $
+** $Id: lstring.c,v 1.78 2002/12/04 17:38:31 roberto Exp roberto $
** String table (keeps all strings handled by Lua)
** See Copyright Notice in lua.h
*/
@@ -34,7 +34,7 @@ void luaS_resize (lua_State *L, int newsize) {
GCObject *p = tb->hash[i];
while (p) { /* for each node in the list */
GCObject *next = p->gch.next; /* save next */
- lu_hash h = gcotots(p)->tsv.hash;
+ unsigned int h = gcotots(p)->tsv.hash;
int h1 = lmod(h, newsize); /* new position */
lua_assert(cast(int, h%newsize) == lmod(h, newsize));
p->gch.next = newhash[h1]; /* chain it */
@@ -48,7 +48,8 @@ void luaS_resize (lua_State *L, int newsize) {
}
-static TString *newlstr (lua_State *L, const char *str, size_t l, lu_hash h) {
+static TString *newlstr (lua_State *L, const char *str, size_t l,
+ unsigned int h) {
TString *ts = cast(TString *, luaM_malloc(L, sizestring(l)));
stringtable *tb;
ts->tsv.len = l;
@@ -63,7 +64,7 @@ static TString *newlstr (lua_State *L, const char *str, size_t l, lu_hash h) {
ts->tsv.next = tb->hash[h]; /* chain new entry */
tb->hash[h] = valtogco(ts);
tb->nuse++;
- if (tb->nuse > cast(ls_nstr, tb->size) && tb->size <= MAX_INT/2)
+ if (tb->nuse > cast(lu_int32, tb->size) && tb->size <= MAX_INT/2)
luaS_resize(L, tb->size*2); /* too crowded */
return ts;
}
@@ -71,7 +72,7 @@ static TString *newlstr (lua_State *L, const char *str, size_t l, lu_hash h) {
TString *luaS_newlstr (lua_State *L, const char *str, size_t l) {
GCObject *o;
- lu_hash h = (lu_hash)l; /* seed */
+ unsigned int h = cast(unsigned int, l); /* seed */
size_t step = (l>>5)+1; /* if string is too long, don't hash all its chars */
size_t l1;
for (l1=l; l1>=step; l1-=step) /* compute hash */
diff --git a/ltable.c b/ltable.c
@@ -1,5 +1,5 @@
/*
-** $Id: ltable.c,v 1.132 2003/04/03 13:35:34 roberto Exp roberto $
+** $Id: ltable.c,v 1.133 2003/04/28 13:31:46 roberto Exp roberto $
** Lua tables (hash)
** See Copyright Notice in lua.h
*/
@@ -85,7 +85,7 @@ static Node *hashnum (const Table *t, lua_Number n) {
lua_assert(sizeof(a) <= sizeof(n));
memcpy(a, &n, sizeof(a));
for (i = 1; i < numints; i++) a[0] += a[i];
- return hashmod(t, cast(lu_hash, a[0]));
+ return hashmod(t, a[0]);
}