|
luaZ_fill discount the byte ,but luaZ_read put it back; it seems unuseful;
why code do not write like this:
int luaZ_fill (ZIO *z) { .... z->n = size - 1; /* discount char being returned */ z->p = buff; return cast_uchar(*(z->p)); } size_t luaZ_read (ZIO *z, void *b, size_t n) { while (n) { size_t m; if (z->n == 0) { /* no bytes in buffer? */ if (luaZ_fill(z) == EOZ) /* try to read more */ return n; /* no more input; return number of missing bytes */ //else { // z->n++; /* luaZ_fill consumed first byte; put it back */ // z->p--; //} } .... } return 0; }why need discount and put it back ? |