** resizes the string table */
| 69 | ** resizes the string table |
| 70 | */ |
| 71 | void luaS_resize (lua_State *L, int newsize) { |
| 72 | int i; |
| 73 | stringtable *tb = &G(L)->strt; |
| 74 | if (newsize > tb->size) { /* grow table if needed */ |
| 75 | luaM_reallocvector(L, tb->hash, tb->size, newsize, TString *); |
| 76 | for (i = tb->size; i < newsize; i++) |
| 77 | tb->hash[i] = NULL; |
| 78 | } |
| 79 | for (i = 0; i < tb->size; i++) { /* rehash */ |
| 80 | TString *p = tb->hash[i]; |
| 81 | tb->hash[i] = NULL; |
| 82 | while (p) { /* for each node in the list */ |
| 83 | TString *hnext = p->u.hnext; /* save next */ |
| 84 | unsigned int h = lmod(p->hash, newsize); /* new position */ |
| 85 | p->u.hnext = tb->hash[h]; /* chain it */ |
| 86 | tb->hash[h] = p; |
| 87 | p = hnext; |
| 88 | } |
| 89 | } |
| 90 | if (newsize < tb->size) { /* shrink table if needed */ |
| 91 | /* vanishing slice should be empty */ |
| 92 | lua_assert(tb->hash[newsize] == NULL && tb->hash[tb->size - 1] == NULL); |
| 93 | luaM_reallocvector(L, tb->hash, tb->size, newsize, TString *); |
| 94 | } |
| 95 | tb->size = newsize; |
| 96 | } |
| 97 | |
| 98 | |
| 99 | /* |
no outgoing calls
no test coverage detected