]> git.saurik.com Git - wxWidgets.git/blobdiff - src/zlib/inffast.c
Changed slightly the meaning of the Hybrid build. It is now
[wxWidgets.git] / src / zlib / inffast.c
index b0737ae5e4eb6e5eaed9cbab825708d8b7c906a4..0e41957fef11d73b5f2b636efc4c5c59b26e5af4 100644 (file)
@@ -1,5 +1,5 @@
 /* inffast.c -- process literals and length/distance pairs fast
 /* inffast.c -- process literals and length/distance pairs fast
- * Copyright (C) 1995-1998 Mark Adler
+ * Copyright (C) 1995-2002 Mark Adler
  * For conditions of distribution and use, see copyright notice in zlib.h
  */
 
  * For conditions of distribution and use, see copyright notice in zlib.h
  */
 
@@ -25,7 +25,7 @@ struct inflate_codes_state {int dummy;}; /* for buggy compilers */
    at least ten.  The ten bytes are six bytes for the longest length/
    distance pair plus four bytes for overloading the bit buffer. */
 
    at least ten.  The ten bytes are six bytes for the longest length/
    distance pair plus four bytes for overloading the bit buffer. */
 
-#if defined(__VISAGECPP__) // Visual game can't handle this antiquated interface
+#if defined(__VISAGECPP__) /* Visualage can't handle this antiquated interface */
 int inflate_fast(uInt bl, uInt bd, inflate_huft* tl, inflate_huft* td, inflate_blocks_statef* s, z_streamp z)
 #else
 int inflate_fast(bl, bd, tl, td, s, z)
 int inflate_fast(uInt bl, uInt bd, inflate_huft* tl, inflate_huft* td, inflate_blocks_statef* s, z_streamp z)
 #else
 int inflate_fast(bl, bd, tl, td, s, z)
@@ -97,28 +97,41 @@ z_streamp z;
 
             /* do the copy */
             m -= c;
 
             /* do the copy */
             m -= c;
-            if ((uInt)(q - s->window) >= d)     /* offset before dest */
-            {                                   /*  just copy */
               r = q - d;
               r = q - d;
-              *q++ = *r++;  c--;        /* minimum count is three, */
-              *q++ = *r++;  c--;        /*  so unroll loop a little */
-            }
-            else                        /* else offset after destination */
+            if (r < s->window)                  /* wrap if needed */
             {
             {
-              e = d - (uInt)(q - s->window); /* bytes from offset to end */
-              r = s->end - e;           /* pointer to offset */
-              if (c > e)                /* if source crosses, */
+              do {
+                r += s->end - s->window;        /* force pointer in window */
+              } while (r < s->window);          /* covers invalid distances */
+              e = s->end - r;
+              if (c > e)
               {
               {
-                c -= e;                 /* copy to end of window */
+                c -= e;                         /* wrapped copy */
                 do {
                   *q++ = *r++;
                 } while (--e);
                 do {
                   *q++ = *r++;
                 } while (--e);
-                r = s->window;          /* copy rest from start of window */
+                r = s->window;
+                do {
+                    *q++ = *r++;
+                } while (--c);
+              }
+              else                              /* normal copy */
+              {
+                *q++ = *r++;  c--;
+                *q++ = *r++;  c--;
+                do {
+                    *q++ = *r++;
+                } while (--c);
               }
             }
               }
             }
-            do {                        /* copy all or what's left */
+            else                                /* normal copy */
+            {
+              *q++ = *r++;  c--;
+              *q++ = *r++;  c--;
+              do {
               *q++ = *r++;
             } while (--c);
               *q++ = *r++;
             } while (--c);
+            }
             break;
           }
           else if ((e & 64) == 0)
             break;
           }
           else if ((e & 64) == 0)