MCPcopy Create free account
hub / github.com/EmmyLua/EmmyLuaDebugger / internshrstr

Function internshrstr

third-party/lua-5.2.4/src/lstring.c:133–150  ·  view source on GitHub ↗

** checks whether short string exists and reuses it or creates a new one */

Source from the content-addressed store, hash-verified

131** checks whether short string exists and reuses it or creates a new one
132*/
133static 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/*

Callers 1

luaS_newlstrFunction · 0.70

Calls 2

newshrstrFunction · 0.85
luaS_hashFunction · 0.70

Tested by

no test coverage detected