** 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. */
| 467 | ** overflow. |
| 468 | */ |
| 469 | static 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 | /* |
no test coverage detected