lichuang / Lua-Source-Internal

Lua source internal
1.45k stars 304 forks source link

Table 里的 lastfree 应该指的是最后那个node的下一个 #12

Open Kuovane opened 2 years ago

Kuovane commented 2 years ago
static void setnodevector (lua_State *L, Table *t, int size) {
  int lsize;
  if (size == 0) {  /* no elements to hash part? */
    t->node = cast(Node *, dummynode);  /* use common `dummynode' */
    lsize = 0;
  }
  else {
    int i;
    lsize = ceillog2(size);
    if (lsize > MAXBITS)
      luaG_runerror(L, "table overflow");
    size = twoto(lsize);
    t->node = luaM_newvector(L, size, Node);
    for (i=0; i<size; i++) {
      Node *n = gnode(t, i);
      gnext(n) = NULL;
      setnilvalue(gkey(n));
      setnilvalue(gval(n));
    }
  }
  t->lsizenode = cast_byte(lsize);
  t->lastfree = gnode(t, size);  /* all positions are free */
}

t->lastfree = gnode(t, size); / all positions are free / 从这行代码可知,lastfree指针指向的那个节点是不可用的; 这个图里的lastfree指向的有点不明确 Table

zouxiaohang commented 2 years ago

邹晓航已经收到了你发送的邮件~~