** resizes the string table */
| 62 | ** resizes the string table |
| 63 | */ |
| 64 | void luaS_resize (lua_State *L, int newsize) { |
| 65 | int i; |
| 66 | stringtable *tb = &G(L)->strt; |
| 67 | /* cannot resize while GC is traversing strings */ |
| 68 | luaC_runtilstate(L, ~bitmask(GCSsweepstring)); |
| 69 | if (newsize > tb->size) { |
| 70 | luaM_reallocvector(L, tb->hash, tb->size, newsize, GCObject *); |
| 71 | for (i = tb->size; i < newsize; i++) tb->hash[i] = NULL; |
| 72 | } |
| 73 | /* rehash */ |
| 74 | for (i=0; i<tb->size; i++) { |
| 75 | GCObject *p = tb->hash[i]; |
| 76 | tb->hash[i] = NULL; |
| 77 | while (p) { /* for each node in the list */ |
| 78 | GCObject *next = gch(p)->next; /* save next */ |
| 79 | unsigned int h = lmod(gco2ts(p)->hash, newsize); /* new position */ |
| 80 | gch(p)->next = tb->hash[h]; /* chain it */ |
| 81 | tb->hash[h] = p; |
| 82 | resetoldbit(p); /* see MOVE OLD rule */ |
| 83 | p = next; |
| 84 | } |
| 85 | } |
| 86 | if (newsize < tb->size) { |
| 87 | /* shrinking slice must be empty */ |
| 88 | lua_assert(tb->hash[newsize] == NULL && tb->hash[tb->size - 1] == NULL); |
| 89 | luaM_reallocvector(L, tb->hash, tb->size, newsize, GCObject *); |
| 90 | } |
| 91 | tb->size = newsize; |
| 92 | } |
| 93 | |
| 94 | |
| 95 | /* |
no test coverage detected