mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Jörn Engel" <joern@wohnheim.fh-wedel.de>
To: Linus Torvalds <torvalds@transmeta.com>
Cc: Steven Cole <elenstev@mesatop.com>, linux-kernel@vger.kernel.org
Subject: [Patch] 2.5.70-bk11 zlib merge #3 inffast.c
Date: Fri, 6 Jun 2003 22:00:51 +0200	[thread overview]
Message-ID: <20030606200051.GI10487@wohnheim.fh-wedel.de> (raw)
In-Reply-To: <20030606192814.GH10487@wohnheim.fh-wedel.de>

Hi Linus!

This patch took me only 30 minutes to verify, too easy! :)

Most of it is reformatting, but the functional bits should fix real
problems.  A loop is introduced, just like in the turboc patch and one
of the three condition bodies has been expanded.

Jörn

-- 
Fancy algorithms are slow when n is small, and n is usually small.
Fancy algorithms have big constants. Until you know that n is
frequently going to be big, don't get fancy.
-- Rob Pike

--- linux-2.5.70-bk11/lib/zlib_inflate/inffast.c~zlib_merge_inffast	2003-06-06 15:56:15.000000000 +0200
+++ linux-2.5.70-bk11/lib/zlib_inflate/inffast.c	2003-06-06 21:53:50.000000000 +0200
@@ -90,28 +90,41 @@
 
             /* do the copy */
             m -= c;
-            if ((uInt)(q - s->window) >= d)     /* offset before dest */
-            {                                   /*  just copy */
-              r = q - d;
-              *q++ = *r++;  c--;        /* minimum count is three, */
-              *q++ = *r++;  c--;        /*  so unroll loop a little */
-            }
-            else                        /* else offset after destination */
+            r = q - d;
+            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++;
+                    *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 */
-              *q++ = *r++;
-            } while (--c);
+            else                                /* normal copy */
+            {
+              *q++ = *r++;  c--;
+              *q++ = *r++;  c--;
+              do {
+                *q++ = *r++;
+              } while (--c);
+            }
             break;
           }
           else if ((e & 64) == 0)

  reply	other threads:[~2003-06-06 19:47 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-06-06 18:31 [Patch] 2.5.70-bk11 zlib cleanup #1 local Jörn Engel
2003-06-06 18:32 ` [Patch] 2.5.70-bk11 zlib cleanup #2 cpp Jörn Engel
2003-06-06 18:39   ` [Patch] 2.5.70-bk11 zlib cleanup #3 Z_NULL Jörn Engel
2003-06-06 18:52     ` [Patch] 2.5.70-bk11 zlib cleanup #4 casts Jörn Engel
2003-06-06 19:23       ` [Patch] 2.5.70-bk11 zlib merge #1 turboc Jörn Engel
2003-06-06 19:28         ` [Patch] 2.5.70-bk11 zlib merge #2 return code Jörn Engel
2003-06-06 20:00           ` Jörn Engel [this message]
2003-06-06 20:13             ` [Patch] 2.5.70-bk11 zlib merge #4 pure magic Jörn Engel
2003-06-06 20:36               ` Bartlomiej Zolnierkiewicz
2003-06-06 21:38                 ` Is there a bug with su, and /dev/std*? J.C. Wren
2003-06-07  9:20                 ` [Patch] 2.5.70-bk11 zlib merge #4 pure magic Jörn Engel
2003-06-07  9:40               ` Paul Mackerras
2003-06-07 10:02                 ` Jörn Engel
2003-06-07 11:42                   ` Paul Mackerras
2003-06-06 18:54     ` [Patch] 2.5.70-bk11 zlib cleanup #3 Z_NULL Linus Torvalds
2003-06-06 19:13       ` Jörn Engel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20030606200051.GI10487@wohnheim.fh-wedel.de \
    --to=joern@wohnheim.fh-wedel.de \
    --cc=elenstev@mesatop.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@transmeta.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®