** checks whether short string exists and reuses it or creates a new one */
| 131 | ** checks whether short string exists and reuses it or creates a new one |
| 132 | */ |
| 133 | static TString *internshrstr (lua_State *L, const char *str, size_t l) { |
| 134 | GCObject *o; |
| 135 | global_State *g = G(L); |
| 136 | unsigned int h = luaS_hash(str, l, g->seed); |
| 137 | for (o = g->strt.hash[lmod(h, g->strt.size)]; |
| 138 | o != NULL; |
| 139 | o = gch(o)->next) { |
| 140 | TString *ts = rawgco2ts(o); |
| 141 | if (h == ts->tsv.hash && |
| 142 | l == ts->tsv.len && |
| 143 | (memcmp(str, getstr(ts), l * sizeof(char)) == 0)) { |
| 144 | if (isdead(G(L), o)) /* string is dead (but was not collected yet)? */ |
| 145 | changewhite(o); /* resurrect it */ |
| 146 | return ts; |
| 147 | } |
| 148 | } |
| 149 | return newshrstr(L, str, l, h); /* not found; create a new string */ |
| 150 | } |
| 151 | |
| 152 | |
| 153 | /* |
no test coverage detected