MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / luaS_newlstr

Function luaS_newlstr

deps/lua/src/lstring.c:75–93  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

73
74
75TString *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
96Udata *luaS_newudata (lua_State *L, size_t s, Table *e) {

Callers 6

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

Calls 1

newlstrFunction · 0.85

Tested by

no test coverage detected