MCPcopy Create free account
hub / github.com/SakuraEngine/SakuraEngine / setnodevector

Function setnodevector

xrepo/packages/l/lua/port/lua/src/ltable.c:478–500  ·  view source on GitHub ↗

** Creates an array for the hash part of a table with the given ** size, or reuses the dummy node if size is zero. ** The computation for size overflow is in two steps: the first ** comparison ensures that the shift in the second one does not ** overflow. */

Source from the content-addressed store, hash-verified

476** overflow.
477*/
478static void setnodevector (lua_State *L, Table *t, unsigned int size) {
479 if (size == 0) { /* no elements to hash part? */
480 t->node = cast(Node *, dummynode); /* use common 'dummynode' */
481 t->lsizenode = 0;
482 t->lastfree = NULL; /* signal that it is using dummy node */
483 }
484 else {
485 int i;
486 int lsize = luaO_ceillog2(size);
487 if (lsize > MAXHBITS || (1u << lsize) > MAXHSIZE)
488 luaG_runerror(L, "table overflow");
489 size = twoto(lsize);
490 t->node = luaM_newvector(L, size, Node);
491 for (i = 0; i < (int)size; i++) {
492 Node *n = gnode(t, i);
493 gnext(n) = 0;
494 setnilkey(n);
495 setempty(gval(n));
496 }
497 t->lsizenode = cast_byte(lsize);
498 t->lastfree = gnode(t, size); /* all positions are free */
499 }
500}
501
502
503/*

Callers 2

luaH_resizeFunction · 0.70
luaH_newFunction · 0.70

Calls 3

luaO_ceillog2Function · 0.85
luaG_runerrorFunction · 0.85
castFunction · 0.50

Tested by

no test coverage detected