diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2001-06-07 12:01:21 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2001-06-07 12:01:21 -0300 |
| commit | ba11831d357889ee090ce92ff508957c6c023c42 (patch) | |
| tree | d54958d74c7fc1d5b751bf4819ed7345e3b6e69b /lstring.c | |
| parent | 190ddd431dd9f14148d232ed9a72db482a1df934 (diff) | |
| download | lua-ba11831d357889ee090ce92ff508957c6c023c42.tar.gz lua-ba11831d357889ee090ce92ff508957c6c023c42.tar.bz2 lua-ba11831d357889ee090ce92ff508957c6c023c42.zip | |
smaller structs for udata and for strings
Diffstat (limited to 'lstring.c')
| -rw-r--r-- | lstring.c | 42 |
1 files changed, 23 insertions, 19 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lstring.c,v 1.62 2001/03/26 14:31:49 roberto Exp roberto $ | 2 | ** $Id: lstring.c,v 1.63 2001/06/06 18:00:19 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 | */ |
| @@ -47,6 +47,27 @@ void luaS_resize (lua_State *L, int newsize) { | |||
| 47 | } | 47 | } |
| 48 | 48 | ||
| 49 | 49 | ||
| 50 | static TString *newlstr (lua_State *L, const l_char *str, size_t l, lu_hash h) { | ||
| 51 | TString *ts = (TString *)luaM_malloc(L, sizestring(l)); | ||
| 52 | stringtable *tb; | ||
| 53 | ts->nexthash = NULL; | ||
| 54 | ts->len = l; | ||
| 55 | ts->hash = h; | ||
| 56 | ts->marked = 0; | ||
| 57 | ts->constindex = 0; | ||
| 58 | memcpy(getstr(ts), str, l*sizeof(l_char)); | ||
| 59 | getstr(ts)[l] = l_c('\0'); /* ending 0 */ | ||
| 60 | tb = &G(L)->strt; | ||
| 61 | h = lmod(h, tb->size); | ||
| 62 | ts->nexthash = tb->hash[h]; /* chain new entry */ | ||
| 63 | tb->hash[h] = ts; | ||
| 64 | tb->nuse++; | ||
| 65 | if (tb->nuse > (ls_nstr)tb->size && tb->size <= MAX_INT/2) | ||
| 66 | luaS_resize(L, tb->size*2); /* too crowded */ | ||
| 67 | return ts; | ||
| 68 | } | ||
| 69 | |||
| 70 | |||
| 50 | TString *luaS_newlstr (lua_State *L, const l_char *str, size_t l) { | 71 | TString *luaS_newlstr (lua_State *L, const l_char *str, size_t l) { |
| 51 | TString *ts; | 72 | TString *ts; |
| 52 | lu_hash h = l; /* seed */ | 73 | lu_hash h = l; /* seed */ |
| @@ -58,29 +79,12 @@ TString *luaS_newlstr (lua_State *L, const l_char *str, size_t l) { | |||
| 58 | if (ts->len == l && (memcmp(str, getstr(ts), l) == 0)) | 79 | if (ts->len == l && (memcmp(str, getstr(ts), l) == 0)) |
| 59 | return ts; | 80 | return ts; |
| 60 | } | 81 | } |
| 61 | /* not found */ | 82 | return newlstr(L, str, l, h); /* not found */ |
| 62 | ts = (TString *)luaM_malloc(L, sizestring(l)); | ||
| 63 | ts->marked = 0; | ||
| 64 | ts->nexthash = NULL; | ||
| 65 | ts->len = l; | ||
| 66 | ts->hash = h; | ||
| 67 | ts->constindex = 0; | ||
| 68 | memcpy(getstr(ts), str, l*sizeof(l_char)); | ||
| 69 | getstr(ts)[l] = 0; /* ending 0 */ | ||
| 70 | h = lmod(h, G(L)->strt.size); | ||
| 71 | ts->nexthash = G(L)->strt.hash[h]; /* chain new entry */ | ||
| 72 | G(L)->strt.hash[h] = ts; | ||
| 73 | G(L)->strt.nuse++; | ||
| 74 | if (G(L)->strt.nuse > (ls_nstr)G(L)->strt.size && | ||
| 75 | G(L)->strt.size <= MAX_INT/2) | ||
| 76 | luaS_resize(L, G(L)->strt.size*2); /* too crowded */ | ||
| 77 | return ts; | ||
| 78 | } | 83 | } |
| 79 | 84 | ||
| 80 | 85 | ||
| 81 | Udata *luaS_newudata (lua_State *L, size_t s) { | 86 | Udata *luaS_newudata (lua_State *L, size_t s) { |
| 82 | Udata *u = (Udata *)luaM_malloc(L, sizeudata(s)); | 87 | Udata *u = (Udata *)luaM_malloc(L, sizeudata(s)); |
| 83 | u->marked = 0; | ||
| 84 | u->len = s; | 88 | u->len = s; |
| 85 | u->tag = 0; | 89 | u->tag = 0; |
| 86 | u->value = ((union L_UUdata *)(u) + 1); | 90 | u->value = ((union L_UUdata *)(u) + 1); |
