** checks whether short string exists and reuses it or creates a new one */
| 120 | ** checks whether short string exists and reuses it or creates a new one |
| 121 | */ |
| 122 | static TString *internshrstr (lua_State *L, const char *str, size_t l) { |
| 123 | TString *ts; |
| 124 | global_State *g = G(L); |
| 125 | unsigned int h = luaS_hash(str, l, g->seed); |
| 126 | TString **list = &g->strt.hash[lmod(h, g->strt.size)]; |
| 127 | for (ts = *list; ts != NULL; ts = ts->hnext) { |
| 128 | if (l == ts->len && |
| 129 | (memcmp(str, getstr(ts), l * sizeof(char)) == 0)) { |
| 130 | /* found! */ |
| 131 | if (isdead(g, ts)) /* dead (but not collected yet)? */ |
| 132 | changewhite(ts); /* resurrect it */ |
| 133 | return ts; |
| 134 | } |
| 135 | } |
| 136 | if (g->strt.nuse >= g->strt.size && g->strt.size <= MAX_INT/2) { |
| 137 | luaS_resize(L, g->strt.size * 2); |
| 138 | list = &g->strt.hash[lmod(h, g->strt.size)]; /* recompute with new size */ |
| 139 | } |
| 140 | ts = createstrobj(L, str, l, LUA_TSHRSTR, h); |
| 141 | ts->hnext = *list; |
| 142 | *list = ts; |
| 143 | g->strt.nuse++; |
| 144 | return ts; |
| 145 | } |
| 146 | |
| 147 | |
| 148 | /* |
no test coverage detected