kernel32 [2/3]: Pull out the DECOMPRESS_ONE_BYTE macro into an inline function

James Hawkins truiken at gmail.com
Fri Nov 17 20:13:51 CST 2006


Hi,

Changelog:
* Pull out the DECOMPRESS_ONE_BYTE macro into an inline function.

 dlls/kernel32/lzexpand.c |  111 +++++++++++++++++++++++++++-------------------
 1 files changed, 64 insertions(+), 47 deletions(-)

-- 
James Hawkins
-------------- next part --------------
diff --git a/dlls/kernel32/lzexpand.c b/dlls/kernel32/lzexpand.c
index b772296..a198459 100644
--- a/dlls/kernel32/lzexpand.c
+++ b/dlls/kernel32/lzexpand.c
@@ -102,7 +102,6 @@ #define IS_LZ_HANDLE(h) (((h) >= LZ_MIN_
 #define GET_LZ_STATE(h) (IS_LZ_HANDLE(h) ? lzstates[(h)-LZ_MIN_HANDLE] : NULL)
 
 /* reads one compressed byte, including buffering */
-#define GET(lzs,b)	_lzget(lzs,&b)
 #define GET_FLUSH(lzs)	lzs->getcur=lzs->getlen;
 
 static int
@@ -322,12 +321,69 @@ INT WINAPI GetExpandedNameW( LPWSTR in, 
     return ret;
 }
 
+static inline INT decompress_one_byte(struct lzstate *lzs, BYTE *b)
+{
+    if (lzs->stringlen)
+    {
+        *b = lzs->table[lzs->stringpos];
+        lzs->stringpos = (lzs->stringpos + 1) & 0xFFF;
+        lzs->stringlen--;
+
+        return 0;
+    }
+
+    if(!(lzs->bytetype & 0x100))
+    {
+        if (_lzget(lzs, b) != 1)
+            return -1;
+
+        lzs->bytetype = *b | 0xFF00;
+    }
+
+    if (lzs->bytetype & 1)
+    {
+        if (_lzget(lzs, b) != 1)
+            return -1;
+    }
+    else
+    {
+        BYTE b1, b2;
+
+        if (_lzget(lzs, &b1) != 1)
+            return -1;
+
+        if (_lzget(lzs, &b2) != 1)
+            return -1;
+
+        /* Format:
+         * b1 b2
+         * AB CD
+         * where CAB is the stringoffset in the table
+         * and D+3 is the len of the string
+         */
+
+        lzs->stringpos = b1 | ((b2 & 0xF0) << 4);
+        lzs->stringlen = (b2 & 0xF) + 2;
+
+        /* 3, but we use a byte already below ... */
+        *b = lzs->table[lzs->stringpos];
+        lzs->stringpos = (lzs->stringpos + 1) & 0xFFF;
+    }
+
+    /* store b in table */
+    lzs->table[lzs->curtabent++] = *b;
+    lzs->curtabent &= 0xFFF;
+    lzs->realcurrent++;
+
+    return 0;
+}
 
 /***********************************************************************
  *           LZRead   (KERNEL32.@)
  */
 INT WINAPI LZRead( HFILE fd, LPSTR vbuf, INT toread )
 {
+	INT res;
 	int	howmuch;
 	BYTE	b,*buf;
 	struct	lzstate	*lzs;
@@ -337,49 +393,6 @@ INT WINAPI LZRead( HFILE fd, LPSTR vbuf,
 	howmuch=toread;
 	if (!(lzs = GET_LZ_STATE(fd))) return _lread(fd,buf,toread);
 
-/* The decompressor itself is in a define, cause we need it twice
- * in this function. (the decompressed byte will be in b)
- */
-#define DECOMPRESS_ONE_BYTE 						\
-		if (lzs->stringlen) {					\
-			b		= lzs->table[lzs->stringpos];	\
-			lzs->stringpos	= (lzs->stringpos+1)&0xFFF;	\
-			lzs->stringlen--;				\
-		} else {						\
-			if (!(lzs->bytetype&0x100)) {			\
-				if (1!=GET(lzs,b)) 			\
-					return toread-howmuch;		\
-				lzs->bytetype = b|0xFF00;		\
-			}						\
-			if (lzs->bytetype & 1) {			\
-				if (1!=GET(lzs,b))			\
-					return toread-howmuch;		\
-			} else {					\
-				BYTE	b1,b2;				\
-									\
-				if (1!=GET(lzs,b1))			\
-					return toread-howmuch;		\
-				if (1!=GET(lzs,b2))			\
-					return toread-howmuch;		\
-				/* Format:				\
-				 * b1 b2				\
-				 * AB CD 				\
-				 * where CAB is the stringoffset in the table\
-				 * and D+3 is the len of the string	\
-				 */					\
-				lzs->stringpos	= b1|((b2&0xf0)<<4);	\
-				lzs->stringlen	= (b2&0xf)+2; 		\
-				/* 3, but we use a  byte already below ... */\
-				b		= lzs->table[lzs->stringpos];\
-				lzs->stringpos	= (lzs->stringpos+1)&0xFFF;\
-			}						\
-			lzs->bytetype>>=1;				\
-		}							\
-		/* store b in table */					\
-		lzs->table[lzs->curtabent++]= b;			\
-		lzs->curtabent	&= 0xFFF;				\
-		lzs->realcurrent++;
-
 	/* if someone has seeked, we have to bring the decompressor
 	 * to that position
 	 */
@@ -399,18 +412,22 @@ #define DECOMPRESS_ONE_BYTE 						\
 			lzs->curtabent	= 0xFF0;
 		}
 		while (lzs->realcurrent<lzs->realwanted) {
-			DECOMPRESS_ONE_BYTE;
+			res = decompress_one_byte(lzs, &b);
+			if (res == -1)
+				return toread - howmuch;
 		}
 	}
 
 	while (howmuch) {
-		DECOMPRESS_ONE_BYTE;
+		res = decompress_one_byte(lzs, &b);
+		if (res == -1)
+			return toread - howmuch;
+
 		lzs->realwanted++;
 		*buf++		= b;
 		howmuch--;
 	}
 	return 	toread;
-#undef DECOMPRESS_ONE_BYTE
 }
 
 
-- 
1.4.2.4


More information about the wine-patches mailing list