diff options
Diffstat (limited to 'lstring.c')
-rw-r--r-- | lstring.c | 10 |
1 files changed, 5 insertions, 5 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lstring.c,v 1.57 2001/02/09 20:22:29 roberto Exp roberto $ | 2 | ** $Id: lstring.c,v 1.58 2001/02/09 20:29:33 roberto Exp roberto $ |
3 | ** String table (keeps all strings handled by Lua) | 3 | ** String table (keeps all strings handled by Lua) |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -39,7 +39,7 @@ void luaS_resize (lua_State *L, stringtable *tb, int newsize) { | |||
39 | TString *p = tb->hash[i]; | 39 | TString *p = tb->hash[i]; |
40 | while (p) { /* for each node in the list */ | 40 | while (p) { /* for each node in the list */ |
41 | TString *next = p->nexthash; /* save next */ | 41 | TString *next = p->nexthash; /* save next */ |
42 | luint32 h = (tb == &G(L)->strt) ? p->u.s.hash : IntPoint(p->u.d.value); | 42 | lu_hash h = (tb == &G(L)->strt) ? p->u.s.hash : IntPoint(p->u.d.value); |
43 | int h1 = lmod(h, newsize); /* new position */ | 43 | int h1 = lmod(h, newsize); /* new position */ |
44 | lua_assert((int)(h%newsize) == lmod(h, newsize)); | 44 | lua_assert((int)(h%newsize) == lmod(h, newsize)); |
45 | p->nexthash = newhash[h1]; /* chain it in new position */ | 45 | p->nexthash = newhash[h1]; /* chain it in new position */ |
@@ -57,7 +57,7 @@ static void newentry (lua_State *L, stringtable *tb, TString *ts, int h) { | |||
57 | ts->nexthash = tb->hash[h]; /* chain new entry */ | 57 | ts->nexthash = tb->hash[h]; /* chain new entry */ |
58 | tb->hash[h] = ts; | 58 | tb->hash[h] = ts; |
59 | tb->nuse++; | 59 | tb->nuse++; |
60 | if (tb->nuse > (luint32)tb->size && tb->size < MAX_INT/2) /* too crowded? */ | 60 | if (tb->nuse > (ls_nstr)tb->size && tb->size <= MAX_INT/2) /* too crowded? */ |
61 | luaS_resize(L, tb, tb->size*2); | 61 | luaS_resize(L, tb, tb->size*2); |
62 | } | 62 | } |
63 | 63 | ||
@@ -65,7 +65,7 @@ static void newentry (lua_State *L, stringtable *tb, TString *ts, int h) { | |||
65 | 65 | ||
66 | TString *luaS_newlstr (lua_State *L, const char *str, size_t l) { | 66 | TString *luaS_newlstr (lua_State *L, const char *str, size_t l) { |
67 | TString *ts; | 67 | TString *ts; |
68 | luint32 h = l; /* seed */ | 68 | lu_hash h = l; /* seed */ |
69 | size_t step = (l>>5)+1; /* if string is too long, don't hash all its chars */ | 69 | size_t step = (l>>5)+1; /* if string is too long, don't hash all its chars */ |
70 | size_t l1; | 70 | size_t l1; |
71 | for (l1=l; l1>=step; l1-=step) /* compute hash */ | 71 | for (l1=l; l1>=step; l1-=step) /* compute hash */ |
@@ -81,7 +81,7 @@ TString *luaS_newlstr (lua_State *L, const char *str, size_t l) { | |||
81 | ts->len = l; | 81 | ts->len = l; |
82 | ts->u.s.hash = h; | 82 | ts->u.s.hash = h; |
83 | ts->u.s.constindex = 0; | 83 | ts->u.s.constindex = 0; |
84 | memcpy(getstr(ts), str, l); | 84 | memcpy(getstr(ts), str, l*sizeof(char)); |
85 | getstr(ts)[l] = 0; /* ending 0 */ | 85 | getstr(ts)[l] = 0; /* ending 0 */ |
86 | newentry(L, &G(L)->strt, ts, lmod(h, G(L)->strt.size)); /* insert it */ | 86 | newentry(L, &G(L)->strt, ts, lmod(h, G(L)->strt.size)); /* insert it */ |
87 | return ts; | 87 | return ts; |