[PATCH 20/20] inflate: make in-core inflate share common CRC

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



inflate: make in-core inflate share common CRC code

Signed-off-by: Matt Mackall <[email protected]>

Index: 2.6.14/lib/inflate.c
===================================================================
--- 2.6.14.orig/lib/inflate.c	2005-10-28 22:04:32.000000000 -0700
+++ 2.6.14/lib/inflate.c	2005-10-28 22:04:35.000000000 -0700
@@ -144,23 +144,46 @@ static void free(void *where)
 		malloc_ptr = free_mem_ptr;
 }
 
-static u8 INITDATA window[0x8000]; /* use a statically allocated window */
+static u8 window[0x8000]; /* use a statically allocated window */
+
+/* simple CRC calculation */
+static u32 crc_32_tab[256];
+#define CRCPOLY_LE 0xedb88320
+
+static void makecrc(void)
+{
+	unsigned i, j;
+	u32 c = 1;
+
+	for (i = 128; i; i >>= 1) {
+		c = (c >> 1) ^ ((c & 1) ? CRCPOLY_LE : 0);
+		for (j = 0; j < 256; j += 2 * i)
+			crc_32_tab[i + j] = c ^ crc_32_tab[j];
+	}
+}
+
+static u32 crc32_le(u32 crc, unsigned char const *p, size_t len)
+{
+	while (len--)
+		crc = crc_32_tab[(*p++ ^ crc) & 0xff] ^ (crc >> 8);
+
+	return crc;
+}
 
 #else
 
 #include <linux/module.h>
+#include <linux/crc32.h>
 
 static u8 *window; /* dynamically allocate */
 #define malloc(a) kmalloc(a, GFP_KERNEL)
 #define free(a) kfree(a)
+#define makecrc()
 #define INIT __init
 #define INITDATA __initdata
 
 #endif
 
-static u32 crc_32_tab[256];
-#define CRCPOLY_LE 0xedb88320
-
 /* Huffman code lookup table entry--this entry is four bytes for machines
    that have 16-bit pointers (e.g. PC's in the small or medium model).
    Valid extra bits are 0..13.  e == 15 is EOB (end of block), e == 16
@@ -205,12 +228,7 @@ static int INIT inflate(struct iostate *
 
 static void flush_output(struct iostate *io)
 {
-	int i;
-
-	for (i = 0; i < io->opos; i++)
-		io->crc = crc_32_tab[(io->window[i] ^ (int)io->crc) & 0xff]
-			^ (io->crc >> 8);
-
+	io->crc = crc32_le(io->crc, io->window, io->opos);
 	io->flush(io->window, io->opos);
 	io->ototal += io->opos;
 	io->opos = 0;
@@ -906,24 +924,6 @@ static int INIT inflate(struct iostate *
 	return 0;
 }
 
-/**********************************************************************
- *
- * The following are support routines for inflate.c
- *
- **********************************************************************/
-
-static void INIT makecrc(void)
-{
-	unsigned i, j;
-	u32 c = 1;
-
-	for (i = 128; i; i >>= 1) {
-		c = (c >> 1) ^ ((c & 1) ? CRCPOLY_LE : 0);
-		for (j = 0; j < 256; j += 2 * i)
-			crc_32_tab[i + j] = c ^ crc_32_tab[j];
-	}
-}
-
 /* gzip flag byte */
 #define ASCII_FLAG   0x01 /* bit 0 set: file probably ASCII text */
 #define CONTINUATION 0x02 /* bit 1 set: continuation of multi-part gzip file */
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux