From eca9fa02d2887d06cee5e2f742f7e3031ac76a51 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Fri, 3 Jun 2005 17:16:16 -0300 Subject: small improvement --- lzio.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) (limited to 'lzio.c') diff --git a/lzio.c b/lzio.c index 176954e3..a09dbdad 100644 --- a/lzio.c +++ b/lzio.c @@ -1,5 +1,5 @@ /* -** $Id: lzio.c,v 1.29 2004/04/30 20:13:38 roberto Exp roberto $ +** $Id: lzio.c,v 1.30 2005/05/17 19:49:15 roberto Exp roberto $ ** a generic input stream interface ** See Copyright Notice in lua.h */ @@ -34,10 +34,12 @@ int luaZ_fill (ZIO *z) { int luaZ_lookahead (ZIO *z) { if (z->n == 0) { - int c = luaZ_fill(z); - if (c == EOZ) return c; - z->n++; - z->p--; + if (luaZ_fill(z) == EOZ) + return EOZ; + else { + z->n++; /* luaZ_fill removed first byte; put back it */ + z->p--; + } } return char2int(*z->p); } @@ -56,14 +58,8 @@ void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, void *data) { size_t luaZ_read (ZIO *z, void *b, size_t n) { while (n) { size_t m; - if (z->n == 0) { - if (luaZ_fill(z) == EOZ) - return n; /* return number of missing bytes */ - else { - ++z->n; /* filbuf removed first byte; put back it */ - --z->p; - } - } + if (luaZ_lookahead(z) == EOZ) + return n; /* return number of missing bytes */ m = (n <= z->n) ? n : z->n; /* min. between n and z->n */ memcpy(b, z->p, m); z->n -= m; -- cgit v1.2.3-55-g6feb