aboutsummaryrefslogtreecommitdiff
path: root/lzio.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2005-06-03 17:16:16 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2005-06-03 17:16:16 -0300
commiteca9fa02d2887d06cee5e2f742f7e3031ac76a51 (patch)
treed3ed46b827c28728ddc2a974391da76af6f990ec /lzio.c
parente33d7bae45f5b29f83f893ba16a7f78d28b77245 (diff)
downloadlua-eca9fa02d2887d06cee5e2f742f7e3031ac76a51.tar.gz
lua-eca9fa02d2887d06cee5e2f742f7e3031ac76a51.tar.bz2
lua-eca9fa02d2887d06cee5e2f742f7e3031ac76a51.zip
small improvement
Diffstat (limited to 'lzio.c')
-rw-r--r--lzio.c22
1 files changed, 9 insertions, 13 deletions
diff --git a/lzio.c b/lzio.c
index 176954e3..a09dbdad 100644
--- a/lzio.c
+++ b/lzio.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lzio.c,v 1.29 2004/04/30 20:13:38 roberto Exp roberto $ 2** $Id: lzio.c,v 1.30 2005/05/17 19:49:15 roberto Exp roberto $
3** a generic input stream interface 3** a generic input stream interface
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -34,10 +34,12 @@ int luaZ_fill (ZIO *z) {
34 34
35int luaZ_lookahead (ZIO *z) { 35int luaZ_lookahead (ZIO *z) {
36 if (z->n == 0) { 36 if (z->n == 0) {
37 int c = luaZ_fill(z); 37 if (luaZ_fill(z) == EOZ)
38 if (c == EOZ) return c; 38 return EOZ;
39 z->n++; 39 else {
40 z->p--; 40 z->n++; /* luaZ_fill removed first byte; put back it */
41 z->p--;
42 }
41 } 43 }
42 return char2int(*z->p); 44 return char2int(*z->p);
43} 45}
@@ -56,14 +58,8 @@ void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, void *data) {
56size_t luaZ_read (ZIO *z, void *b, size_t n) { 58size_t luaZ_read (ZIO *z, void *b, size_t n) {
57 while (n) { 59 while (n) {
58 size_t m; 60 size_t m;
59 if (z->n == 0) { 61 if (luaZ_lookahead(z) == EOZ)
60 if (luaZ_fill(z) == EOZ) 62 return n; /* return number of missing bytes */
61 return n; /* return number of missing bytes */
62 else {
63 ++z->n; /* filbuf removed first byte; put back it */
64 --z->p;
65 }
66 }
67 m = (n <= z->n) ? n : z->n; /* min. between n and z->n */ 63 m = (n <= z->n) ? n : z->n; /* min. between n and z->n */
68 memcpy(b, z->p, m); 64 memcpy(b, z->p, m);
69 z->n -= m; 65 z->n -= m;