summaryrefslogtreecommitdiff
path: root/src/lstring.c
diff options
context:
space:
mode:
authorLua Team <team@lua.org>2004-03-24 12:00:00 +0000
committerrepogen <>2004-03-24 12:00:00 +0000
commitced7bbbe7a257ce6de94069d5dbf6672aeafd4d9 (patch)
tree2a01a79e6a4f451dccd247c70310ad957204cefa /src/lstring.c
parente7731a8fb8a317aa5c444ef073bfad82fa5baa54 (diff)
downloadlua-github-5.1-work0.tar.gz
Lua 5.1-work05.1-work0
Diffstat (limited to 'src/lstring.c')
-rw-r--r--src/lstring.c37
1 files changed, 22 insertions, 15 deletions
diff --git a/src/lstring.c b/src/lstring.c
index 8cbddbd2..9a26cf03 100644
--- a/src/lstring.c
+++ b/src/lstring.c
@@ -1,5 +1,5 @@
/*
-** $Id: lstring.c,v 1.78 2002/12/04 17:38:31 roberto Exp $
+** $Id: lstring.c,v 2.1 2003/12/10 12:13:36 roberto Exp $
** String table (keeps all strings handled by Lua)
** See Copyright Notice in lua.h
*/
@@ -25,16 +25,19 @@ void luaS_freeall (lua_State *L) {
void luaS_resize (lua_State *L, int newsize) {
- GCObject **newhash = luaM_newvector(L, newsize, GCObject *);
- stringtable *tb = &G(L)->strt;
+ GCObject **newhash;
+ stringtable *tb;
int i;
+ if (G(L)->sweepstrgc > 0) return; /* cannot resize during GC traverse */
+ newhash = luaM_newvector(L, newsize, GCObject *);
+ tb = &G(L)->strt;
for (i=0; i<newsize; i++) newhash[i] = NULL;
/* rehash */
for (i=0; i<tb->size; i++) {
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 = gco2ts(p)->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,12 +51,13 @@ 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;
ts->tsv.hash = h;
- ts->tsv.marked = 0;
+ ts->tsv.marked = luaC_white(G(L));
ts->tsv.tt = LUA_TSTRING;
ts->tsv.reserved = 0;
memcpy(ts+1, str, l*sizeof(char));
@@ -61,9 +65,9 @@ static TString *newlstr (lua_State *L, const char *str, size_t l, lu_hash h) {
tb = &G(L)->strt;
h = lmod(h, tb->size);
ts->tsv.next = tb->hash[h]; /* chain new entry */
- tb->hash[h] = valtogco(ts);
+ tb->hash[h] = obj2gco(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 +75,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 */
@@ -79,9 +83,12 @@ TString *luaS_newlstr (lua_State *L, const char *str, size_t l) {
for (o = G(L)->strt.hash[lmod(h, G(L)->strt.size)];
o != NULL;
o = o->gch.next) {
- TString *ts = gcotots(o);
- if (ts->tsv.len == l && (memcmp(str, getstr(ts), l) == 0))
+ TString *ts = rawgco2ts(o);
+ if (ts->tsv.len == l && (memcmp(str, getstr(ts), l) == 0)) {
+ /* string may be dead */
+ if (isdead(G(L), o)) changewhite(o);
return ts;
+ }
}
return newlstr(L, str, l, h); /* not found */
}
@@ -90,13 +97,13 @@ TString *luaS_newlstr (lua_State *L, const char *str, size_t l) {
Udata *luaS_newudata (lua_State *L, size_t s) {
Udata *u;
u = cast(Udata *, luaM_malloc(L, sizeudata(s)));
- u->uv.marked = (1<<1); /* is not finalized */
+ u->uv.marked = luaC_white(G(L)); /* is not finalized */
u->uv.tt = LUA_TUSERDATA;
u->uv.len = s;
- u->uv.metatable = hvalue(defaultmeta(L));
+ u->uv.metatable = NULL;
/* chain it on udata list */
- u->uv.next = G(L)->rootudata;
- G(L)->rootudata = valtogco(u);
+ u->uv.next = G(L)->firstudata->uv.next;
+ G(L)->firstudata->uv.next = obj2gco(u);
return u;
}