MCPcopy Create free account
hub / github.com/F-Stack/f-stack / internshrstr

Function internshrstr

freebsd/contrib/openzfs/module/lua/lstring.c:134–151  ·  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

132** checks whether short string exists and reuses it or creates a new one
133*/
134static TString *internshrstr (lua_State *L, const char *str, size_t l) {
135 GCObject *o;
136 global_State *g = G(L);
137 unsigned int h = luaS_hash(str, l, g->seed);
138 for (o = g->strt.hash[lmod(h, g->strt.size)];
139 o != NULL;
140 o = gch(o)->next) {
141 TString *ts = rawgco2ts(o);
142 if (h == ts->tsv.hash &&
143 l == ts->tsv.len &&
144 (memcmp(str, getstr(ts), l * sizeof(char)) == 0)) {
145 if (isdead(G(L), o)) /* string is dead (but was not collected yet)? */
146 changewhite(o); /* resurrect it */
147 return ts;
148 }
149 }
150 return newshrstr(L, str, l, h); /* not found; create a new string */
151}
152
153
154/*

Callers 1

luaS_newlstrFunction · 0.85

Calls 2

luaS_hashFunction · 0.85
newshrstrFunction · 0.85

Tested by

no test coverage detected