MCPcopy Create free account
hub / github.com/RomanKubiak/ctrlr / luaS_newlstr

Function luaS_newlstr

Source/Misc/lua/src/lua.c:9204–9222  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9202
9203
9204TString *luaS_newlstr (lua_State *L, const char *str, size_t l) {
9205GCObject *o;
9206unsigned int h = cast(unsigned int, l); /* seed */
9207size_t step = (l>>5)+1; /* if string is too long, don't hash all its chars */
9208size_t l1;
9209for (l1=l; l1>=step; l1-=step) /* compute hash */
9210h = h ^ ((h<<5)+(h>>2)+cast(unsigned char, str[l1-1]));
9211for (o = G(L)->strt.hash[lmod(h, G(L)->strt.size)];
9212o != NULL;
9213o = o->gch.next) {
9214TString *ts = rawgco2ts(o);
9215if (ts->tsv.len == l && (memcmp(str, getstr(ts), l) == 0)) {
9216/* string may be dead */
9217if (isdead(G(L), o)) changewhite(o);
9218return ts;
9219}
9220}
9221return newlstr(L, str, l, h); /* not found */
9222}
9223
9224
9225Udata *luaS_newudata (lua_State *L, size_t s, Table *e) {

Callers 6

lua_pushlstringFunction · 0.85
lua_concatFunction · 0.85
luaX_newstringFunction · 0.85
luaO_pushvfstringFunction · 0.85
LoadStringFunction · 0.85
luaV_concatFunction · 0.85

Calls 1

newlstrFunction · 0.85

Tested by

no test coverage detected