** Create or reuse a zero-terminated string, first checking in the ** cache (using the string address as a key). The cache can contain ** only zero-terminated strings, so it is safe to use 'strcmp' to ** check hits. */
| 199 | ** check hits. |
| 200 | */ |
| 201 | TString *luaS_new (lua_State *L, const char *str) { |
| 202 | unsigned int i = point2uint(str) % STRCACHE_SIZE; /* hash */ |
| 203 | TString **p = G(L)->strcache[i]; |
| 204 | if (strcmp(str, getstr(p[0])) == 0) /* hit? */ |
| 205 | return p[0]; /* that it is */ |
| 206 | else { /* normal route */ |
| 207 | TString *s = luaS_newlstr(L, str, strlen(str)); |
| 208 | p[0] = s; |
| 209 | return s; |
| 210 | } |
| 211 | } |
| 212 | |
| 213 | |
| 214 | Udata *luaS_newudata (lua_State *L, size_t s) { |
no test coverage detected