MCPcopy Create free account
hub / github.com/CppCXY/EmmyLuaCodeStyle / setnodevector

Function setnodevector

3rd/lua-5.4.3/src/ltable.c:469–491  ·  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

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

Callers 2

luaH_resizeFunction · 0.85
luaH_newFunction · 0.85

Calls 2

luaO_ceillog2Function · 0.85
luaG_runerrorFunction · 0.85

Tested by

no test coverage detected