diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2000-03-10 15:37:44 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2000-03-10 15:37:44 -0300 |
| commit | 73aa465a8ed8dee6c6a27a6f8b2f51227b70789d (patch) | |
| tree | 496a63ffffe0312f1d0b9882d97944fa38ed7801 /lstring.c | |
| parent | 3d0577f4b98908be3f2d697ab75c5fbbd3f6999b (diff) | |
| download | lua-73aa465a8ed8dee6c6a27a6f8b2f51227b70789d.tar.gz lua-73aa465a8ed8dee6c6a27a6f8b2f51227b70789d.tar.bz2 lua-73aa465a8ed8dee6c6a27a6f8b2f51227b70789d.zip | |
some name changes
Diffstat (limited to 'lstring.c')
| -rw-r--r-- | lstring.c | 52 |
1 files changed, 26 insertions, 26 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lstring.c,v 1.32 2000/03/03 14:58:26 roberto Exp roberto $ | 2 | ** $Id: lstring.c,v 1.33 2000/03/10 14:38:10 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 | */ |
| @@ -17,7 +17,7 @@ | |||
| 17 | 17 | ||
| 18 | 18 | ||
| 19 | 19 | ||
| 20 | #define gcsizestring(L, l) numblocks(L, 0, sizeof(TaggedString)+l) | 20 | #define gcsizestring(L, l) numblocks(L, 0, sizeof(TString)+l) |
| 21 | #define gcsizeudata gcsizestring(L, 0) | 21 | #define gcsizeudata gcsizestring(L, 0) |
| 22 | 22 | ||
| 23 | 23 | ||
| @@ -28,7 +28,7 @@ void luaS_init (lua_State *L) { | |||
| 28 | for (i=0; i<NUM_HASHS; i++) { | 28 | for (i=0; i<NUM_HASHS; i++) { |
| 29 | L->string_root[i].size = 1; | 29 | L->string_root[i].size = 1; |
| 30 | L->string_root[i].nuse = 0; | 30 | L->string_root[i].nuse = 0; |
| 31 | L->string_root[i].hash = luaM_newvector(L, 1, TaggedString *);; | 31 | L->string_root[i].hash = luaM_newvector(L, 1, TString *);; |
| 32 | L->string_root[i].hash[0] = NULL; | 32 | L->string_root[i].hash[0] = NULL; |
| 33 | } | 33 | } |
| 34 | } | 34 | } |
| @@ -54,14 +54,14 @@ static unsigned long hash_s (const char *s, long l) { | |||
| 54 | 54 | ||
| 55 | 55 | ||
| 56 | void luaS_resize (lua_State *L, stringtable *tb, int newsize) { | 56 | void luaS_resize (lua_State *L, stringtable *tb, int newsize) { |
| 57 | TaggedString **newhash = luaM_newvector(L, newsize, TaggedString *); | 57 | TString **newhash = luaM_newvector(L, newsize, TString *); |
| 58 | int i; | 58 | int i; |
| 59 | for (i=0; i<newsize; i++) newhash[i] = NULL; | 59 | for (i=0; i<newsize; i++) newhash[i] = NULL; |
| 60 | /* rehash */ | 60 | /* rehash */ |
| 61 | for (i=0; i<tb->size; i++) { | 61 | for (i=0; i<tb->size; i++) { |
| 62 | TaggedString *p = tb->hash[i]; | 62 | TString *p = tb->hash[i]; |
| 63 | while (p) { /* for each node in the list */ | 63 | while (p) { /* for each node in the list */ |
| 64 | TaggedString *next = p->nexthash; /* save next */ | 64 | TString *next = p->nexthash; /* save next */ |
| 65 | int h = p->hash&(newsize-1); /* new position */ | 65 | int h = p->hash&(newsize-1); /* new position */ |
| 66 | LUA_ASSERT(L, p->hash%newsize == (p->hash&(newsize-1)), | 66 | LUA_ASSERT(L, p->hash%newsize == (p->hash&(newsize-1)), |
| 67 | "a&(x-1) == a%x, for x power of 2"); | 67 | "a&(x-1) == a%x, for x power of 2"); |
| @@ -76,9 +76,9 @@ void luaS_resize (lua_State *L, stringtable *tb, int newsize) { | |||
| 76 | } | 76 | } |
| 77 | 77 | ||
| 78 | 78 | ||
| 79 | static TaggedString *newone (lua_State *L, long l, unsigned long h) { | 79 | static TString *newone (lua_State *L, long l, unsigned long h) { |
| 80 | TaggedString *ts = (TaggedString *)luaM_malloc(L, | 80 | TString *ts = (TString *)luaM_malloc(L, |
| 81 | sizeof(TaggedString)+l*sizeof(char)); | 81 | sizeof(TString)+l*sizeof(char)); |
| 82 | ts->marked = 0; | 82 | ts->marked = 0; |
| 83 | ts->nexthash = NULL; | 83 | ts->nexthash = NULL; |
| 84 | ts->hash = h; | 84 | ts->hash = h; |
| @@ -86,9 +86,9 @@ static TaggedString *newone (lua_State *L, long l, unsigned long h) { | |||
| 86 | } | 86 | } |
| 87 | 87 | ||
| 88 | 88 | ||
| 89 | static TaggedString *newone_s (lua_State *L, const char *str, | 89 | static TString *newone_s (lua_State *L, const char *str, |
| 90 | long l, unsigned long h) { | 90 | long l, unsigned long h) { |
| 91 | TaggedString *ts = newone(L, l, h); | 91 | TString *ts = newone(L, l, h); |
| 92 | memcpy(ts->str, str, l); | 92 | memcpy(ts->str, str, l); |
| 93 | ts->str[l] = 0; /* ending 0 */ | 93 | ts->str[l] = 0; /* ending 0 */ |
| 94 | ts->u.s.gv = NULL; /* no global value */ | 94 | ts->u.s.gv = NULL; /* no global value */ |
| @@ -99,9 +99,9 @@ static TaggedString *newone_s (lua_State *L, const char *str, | |||
| 99 | } | 99 | } |
| 100 | 100 | ||
| 101 | 101 | ||
| 102 | static TaggedString *newone_u (lua_State *L, void *buff, | 102 | static TString *newone_u (lua_State *L, void *buff, |
| 103 | int tag, unsigned long h) { | 103 | int tag, unsigned long h) { |
| 104 | TaggedString *ts = newone(L, 0, h); | 104 | TString *ts = newone(L, 0, h); |
| 105 | ts->u.d.value = buff; | 105 | ts->u.d.value = buff; |
| 106 | ts->u.d.tag = (tag == LUA_ANYTAG) ? 0 : tag; | 106 | ts->u.d.tag = (tag == LUA_ANYTAG) ? 0 : tag; |
| 107 | ts->constindex = -1; /* tag -> this is a userdata */ | 107 | ts->constindex = -1; /* tag -> this is a userdata */ |
| @@ -110,7 +110,7 @@ static TaggedString *newone_u (lua_State *L, void *buff, | |||
| 110 | } | 110 | } |
| 111 | 111 | ||
| 112 | 112 | ||
| 113 | static void newentry (lua_State *L, stringtable *tb, TaggedString *ts, int h) { | 113 | static void newentry (lua_State *L, stringtable *tb, TString *ts, int h) { |
| 114 | ts->nexthash = tb->hash[h]; /* chain new entry */ | 114 | ts->nexthash = tb->hash[h]; /* chain new entry */ |
| 115 | tb->hash[h] = ts; | 115 | tb->hash[h] = ts; |
| 116 | tb->nuse++; | 116 | tb->nuse++; |
| @@ -119,12 +119,12 @@ static void newentry (lua_State *L, stringtable *tb, TaggedString *ts, int h) { | |||
| 119 | } | 119 | } |
| 120 | 120 | ||
| 121 | 121 | ||
| 122 | TaggedString *luaS_newlstr (lua_State *L, const char *str, long l) { | 122 | TString *luaS_newlstr (lua_State *L, const char *str, long l) { |
| 123 | unsigned long h = hash_s(str, l); | 123 | unsigned long h = hash_s(str, l); |
| 124 | stringtable *tb = &L->string_root[(l==0) ? 0 : | 124 | stringtable *tb = &L->string_root[(l==0) ? 0 : |
| 125 | ((unsigned int)(str[0]+str[l-1]))&(NUM_HASHSTR-1)]; | 125 | ((unsigned int)(str[0]+str[l-1]))&(NUM_HASHSTR-1)]; |
| 126 | int h1 = h&(tb->size-1); | 126 | int h1 = h&(tb->size-1); |
| 127 | TaggedString *ts; | 127 | TString *ts; |
| 128 | for (ts = tb->hash[h1]; ts; ts = ts->nexthash) { | 128 | for (ts = tb->hash[h1]; ts; ts = ts->nexthash) { |
| 129 | if (ts->u.s.len == l && (memcmp(str, ts->str, l) == 0)) | 129 | if (ts->u.s.len == l && (memcmp(str, ts->str, l) == 0)) |
| 130 | return ts; | 130 | return ts; |
| @@ -140,11 +140,11 @@ TaggedString *luaS_newlstr (lua_State *L, const char *str, long l) { | |||
| 140 | ** uses '%' for one hashing with userdata because addresses are too regular, | 140 | ** uses '%' for one hashing with userdata because addresses are too regular, |
| 141 | ** so two '&' operations would be highly correlated | 141 | ** so two '&' operations would be highly correlated |
| 142 | */ | 142 | */ |
| 143 | TaggedString *luaS_createudata (lua_State *L, void *udata, int tag) { | 143 | TString *luaS_createudata (lua_State *L, void *udata, int tag) { |
| 144 | unsigned long h = IntPoint(L, udata); | 144 | unsigned long h = IntPoint(L, udata); |
| 145 | stringtable *tb = &L->string_root[(h%NUM_HASHUDATA)+NUM_HASHSTR]; | 145 | stringtable *tb = &L->string_root[(h%NUM_HASHUDATA)+NUM_HASHSTR]; |
| 146 | int h1 = h&(tb->size-1); | 146 | int h1 = h&(tb->size-1); |
| 147 | TaggedString *ts; | 147 | TString *ts; |
| 148 | for (ts = tb->hash[h1]; ts; ts = ts->nexthash) { | 148 | for (ts = tb->hash[h1]; ts; ts = ts->nexthash) { |
| 149 | if (udata == ts->u.d.value && (tag == ts->u.d.tag || tag == LUA_ANYTAG)) | 149 | if (udata == ts->u.d.value && (tag == ts->u.d.tag || tag == LUA_ANYTAG)) |
| 150 | return ts; | 150 | return ts; |
| @@ -156,18 +156,18 @@ TaggedString *luaS_createudata (lua_State *L, void *udata, int tag) { | |||
| 156 | } | 156 | } |
| 157 | 157 | ||
| 158 | 158 | ||
| 159 | TaggedString *luaS_new (lua_State *L, const char *str) { | 159 | TString *luaS_new (lua_State *L, const char *str) { |
| 160 | return luaS_newlstr(L, str, strlen(str)); | 160 | return luaS_newlstr(L, str, strlen(str)); |
| 161 | } | 161 | } |
| 162 | 162 | ||
| 163 | TaggedString *luaS_newfixed (lua_State *L, const char *str) { | 163 | TString *luaS_newfixed (lua_State *L, const char *str) { |
| 164 | TaggedString *ts = luaS_new(L, str); | 164 | TString *ts = luaS_new(L, str); |
| 165 | if (ts->marked == 0) ts->marked = FIXMARK; /* avoid GC */ | 165 | if (ts->marked == 0) ts->marked = FIXMARK; /* avoid GC */ |
| 166 | return ts; | 166 | return ts; |
| 167 | } | 167 | } |
| 168 | 168 | ||
| 169 | 169 | ||
| 170 | void luaS_free (lua_State *L, TaggedString *t) { | 170 | void luaS_free (lua_State *L, TString *t) { |
| 171 | if (t->constindex == -1) /* is userdata? */ | 171 | if (t->constindex == -1) /* is userdata? */ |
| 172 | L->nblocks -= gcsizeudata; | 172 | L->nblocks -= gcsizeudata; |
| 173 | else { /* is string */ | 173 | else { /* is string */ |
| @@ -178,11 +178,11 @@ void luaS_free (lua_State *L, TaggedString *t) { | |||
| 178 | } | 178 | } |
| 179 | 179 | ||
| 180 | 180 | ||
| 181 | GlobalVar *luaS_assertglobal (lua_State *L, TaggedString *ts) { | 181 | GlobalVar *luaS_assertglobal (lua_State *L, TString *ts) { |
| 182 | GlobalVar *gv = ts->u.s.gv; | 182 | GlobalVar *gv = ts->u.s.gv; |
| 183 | if (!gv) { /* no global value yet? */ | 183 | if (!gv) { /* no global value yet? */ |
| 184 | gv = luaM_new(L, GlobalVar); | 184 | gv = luaM_new(L, GlobalVar); |
| 185 | gv->value.ttype = LUA_T_NIL; /* initial value */ | 185 | gv->value.ttype = TAG_NIL; /* initial value */ |
| 186 | gv->name = ts; | 186 | gv->name = ts; |
| 187 | gv->next = L->rootglobal; /* chain in global list */ | 187 | gv->next = L->rootglobal; /* chain in global list */ |
| 188 | L->rootglobal = gv; | 188 | L->rootglobal = gv; |
| @@ -198,8 +198,8 @@ GlobalVar *luaS_assertglobalbyname (lua_State *L, const char *name) { | |||
| 198 | 198 | ||
| 199 | 199 | ||
| 200 | int luaS_globaldefined (lua_State *L, const char *name) { | 200 | int luaS_globaldefined (lua_State *L, const char *name) { |
| 201 | TaggedString *ts = luaS_new(L, name); | 201 | TString *ts = luaS_new(L, name); |
| 202 | return ts->u.s.gv && ts->u.s.gv->value.ttype != LUA_T_NIL; | 202 | return ts->u.s.gv && ts->u.s.gv->value.ttype != TAG_NIL; |
| 203 | } | 203 | } |
| 204 | 204 | ||
| 205 | 205 | ||
