| 9149 | |
| 9150 | |
| 9151 | void luaS_resize (lua_State *L, int newsize) { |
| 9152 | GCObject **newhash; |
| 9153 | stringtable *tb; |
| 9154 | int i; |
| 9155 | if (G(L)->gcstate == GCSsweepstring) |
| 9156 | return; /* cannot resize during GC traverse */ |
| 9157 | newhash = luaM_newvector(L, newsize, GCObject *); |
| 9158 | tb = &G(L)->strt; |
| 9159 | for (i=0; i<newsize; i++) newhash[i] = NULL; |
| 9160 | /* rehash */ |
| 9161 | for (i=0; i<tb->size; i++) { |
| 9162 | GCObject *p = tb->hash[i]; |
| 9163 | while (p) { /* for each node in the list */ |
| 9164 | GCObject *next = p->gch.next; /* save next */ |
| 9165 | unsigned int h = gco2ts(p)->hash; |
| 9166 | int h1 = lmod(h, newsize); /* new position */ |
| 9167 | lua_assert(cast_int(h%newsize) == lmod(h, newsize)); |
| 9168 | p->gch.next = newhash[h1]; /* chain it */ |
| 9169 | newhash[h1] = p; |
| 9170 | p = next; |
| 9171 | } |
| 9172 | } |
| 9173 | luaM_freearray(L, tb->hash, tb->size, TString *); |
| 9174 | tb->size = newsize; |
| 9175 | tb->hash = newhash; |
| 9176 | } |
| 9177 | |
| 9178 | |
| 9179 | static TString *newlstr (lua_State *L, const char *str, size_t l, |
no outgoing calls
no test coverage detected