Cloud Stack Ninja

int luaZ_fill (ZIO *z) {
  ....
  z->n = size - 1; 
  z->p = buff;
  return char2int(*(z->p++));
}
int luaZ_lookahead (ZIO *z) {
  if (z->n == 0) {
    if (luaZ_fill(z) == EOZ)
      return EOZ;
    else {
      z->n++;  /* luaZ_fill removed first byte; put back it */
      z->p--;
    }
  }
  return char2int(*z->p);
}

the function luaZ_fill read data from reader,but why z->n = size - 1 need -1 ,it seems unuseful.because the functon luaZ_lookahead which called luaZ_fill put back it. why the code do not write like this:

int luaZ_fill (ZIO *z) {
  ....
  z->n = size; 
  z->p = buff;
  return char2int(*(z->p));
}
int luaZ_lookahead (ZIO *z) {
  if (z->n == 0) {
    if (luaZ_fill(z) == EOZ)
      return EOZ;
  }
  return char2int(*z->p);
}


Read more here: https://stackoverflow.com/questions/64400312/why-lua-luaz-fill-read-data-like-this

Content Attribution

This content was originally published by maike at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: