| 20 | |
| 21 | |
| 22 | void luaS_resize (lua_State *L, int newsize) { |
| 23 | GCObject **newhash; |
| 24 | stringtable *tb; |
| 25 | int i; |
| 26 | if (G(L)->gcstate == GCSsweepstring) |
| 27 | return; /* cannot resize during GC traverse */ |
| 28 | newhash = luaM_newvector(L, newsize, GCObject *); |
| 29 | tb = &G(L)->strt; |
| 30 | for (i=0; i<newsize; i++) newhash[i] = NULL; |
| 31 | /* rehash */ |
| 32 | for (i=0; i<tb->size; i++) { |
| 33 | GCObject *p = tb->hash[i]; |
| 34 | while (p) { /* for each node in the list */ |
| 35 | GCObject *next = p->gch.next; /* save next */ |
| 36 | unsigned int h = gco2ts(p)->hash; |
| 37 | int h1 = lmod(h, newsize); /* new position */ |
| 38 | lua_assert(cast_int(h%newsize) == lmod(h, newsize)); |
| 39 | p->gch.next = newhash[h1]; /* chain it */ |
| 40 | newhash[h1] = p; |
| 41 | p = next; |
| 42 | } |
| 43 | } |
| 44 | luaM_freearray(L, tb->hash, tb->size, TString *); |
| 45 | tb->size = newsize; |
| 46 | tb->hash = newhash; |
| 47 | } |
| 48 | |
| 49 | |
| 50 | static TString *newlstr (lua_State *L, const char *str, size_t l, |
no test coverage detected