| 73 | |
| 74 | |
| 75 | TString *luaS_newlstr (lua_State *L, const char *str, size_t l) { |
| 76 | GCObject *o; |
| 77 | unsigned int h = cast(unsigned int, l); /* seed */ |
| 78 | size_t step = (l>>5)+1; /* if string is too long, don't hash all its chars */ |
| 79 | size_t l1; |
| 80 | for (l1=l; l1>=step; l1-=step) /* compute hash */ |
| 81 | h = h ^ ((h<<5)+(h>>2)+cast(unsigned char, str[l1-1])); |
| 82 | for (o = G(L)->strt.hash[lmod(h, G(L)->strt.size)]; |
| 83 | o != NULL; |
| 84 | o = o->gch.next) { |
| 85 | TString *ts = rawgco2ts(o); |
| 86 | if (ts->tsv.len == l && (memcmp(str, getstr(ts), l) == 0)) { |
| 87 | /* string may be dead */ |
| 88 | if (isdead(G(L), o)) changewhite(o); |
| 89 | return ts; |
| 90 | } |
| 91 | } |
| 92 | return newlstr(L, str, l, h); /* not found */ |
| 93 | } |
| 94 | |
| 95 | |
| 96 | Udata *luaS_newudata (lua_State *L, size_t s, Table *e) { |
no test coverage detected