** 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. */
| 434 | ** overflow. |
| 435 | */ |
| 436 | static void setnodevector (lua_State *L, Table *t, unsigned int size) { |
| 437 | if (size == 0) { /* no elements to hash part? */ |
| 438 | t->node = cast(Node *, dummynode); /* use common 'dummynode' */ |
| 439 | t->lsizenode = 0; |
| 440 | t->lastfree = NULL; /* signal that it is using dummy node */ |
| 441 | } |
| 442 | else { |
| 443 | int i; |
| 444 | int lsize = luaO_ceillog2(size); |
| 445 | if (lsize > MAXHBITS || (1u << lsize) > MAXHSIZE) |
| 446 | luaG_runerror(L, "table overflow"); |
| 447 | size = twoto(lsize); |
| 448 | t->node = luaM_newvector(L, size, Node); |
| 449 | for (i = 0; i < (int)size; i++) { |
| 450 | Node *n = gnode(t, i); |
| 451 | gnext(n) = 0; |
| 452 | setnilkey(n); |
| 453 | setempty(gval(n)); |
| 454 | } |
| 455 | t->lsizenode = cast_byte(lsize); |
| 456 | t->lastfree = gnode(t, size); /* all positions are free */ |
| 457 | } |
| 458 | } |
| 459 | |
| 460 | |
| 461 | /* |
no test coverage detected