bug-gzip
[Top][All Lists]
Advanced

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

RE: gzip use of memcpy


From: Yuxi Zhang
Subject: RE: gzip use of memcpy
Date: Mon, 11 Jan 2010 12:43:43 -0500

Hi Jim

It would be nice to declare the delta inside the function scope.

Index: inflate.c
===================================================================
--- inflate.c   (revision 248271)
+++ inflate.c   (working copy)
@@ -526,6 +526,7 @@
   register unsigned e;  /* table entry flag/number of extra bits */
   unsigned n, d;        /* length and index for copy */
   unsigned w;           /* current window position */
+  unsigned delta;       /* delta between slide+w and slide+d */
   struct huft *t;       /* pointer to table entry */
   unsigned ml, md;      /* masks for bl and bd bits */
   register ulg b;       /* bit buffer */
@@ -593,7 +594,9 @@
       do {
         n -= (e = (e = WSIZE - ((d &= WSIZE-1) > w ? d : w)) > n ? n :
e);
 #if !defined(NOMEMCPY) && !defined(DEBUG)
-        if (w - d >= e)         /* (this test assumes unsigned
comparison) */
+        /* make the unsigned comparision in positive range. */
+        delta = w > d ? w - d : d - w;
+        if (delta >= e)         /* (this test assumes unsigned
comparison) */
         {
           memcpy(slide + w, slide + d, e);
           w += e;


Thanks
Yuxi



> -----Original Message-----
> From: Jim Meyering [mailto:address@hidden 
> Sent: January 11, 2010 12:32 PM
> To: Alain Magloire
> Cc: Yuxi Zhang; address@hidden
> Subject: Re: gzip use of memcpy
> 
> Alain Magloire wrote:
> 
> > Bonjour,
> >
> >   Our tester (Yuxi) was proposing something along this line 
> to check 
> > for overlapping.
> >
> > ===email from yuxi===
> > We could do a smart checking here:
> > Unsigned int delta = w > d ? w -d : d -w;
> >         if (delta >= e)         /* (this test assumes unsigned
> > comparison) */
> >         {
> >           memcpy(slide + w, slide + d, e);
> >           w += e;
> >           d += e;
> >         }
> >         else                      /* do it slow to avoid memcpy()
> > overlap */
> 
> Good idea.  Thank you!
> How about the patch below?
> I realize that it introduces a c99-ism (stmt after decl), but 
> experience with coreutils has shown that that is no longer a 
> problem in practice.
> 
> From 17822e2cab5e47d73f224a688be8013c34f990f7 Mon Sep 17 00:00:00 2001
> From: Yuxi Zhang <address@hidden>
> Date: Mon, 11 Jan 2010 18:28:30 +0100
> Subject: [PATCH] gzip -d: use memcpy more often
> 
> * inflate.c (inflate_codes): Use memcpy (rather than slower 
> memcopy-like code) in more cases.
> ---
>  inflate.c |    3 ++-
>  1 files changed, 2 insertions(+), 1 deletions(-)
> 
> diff --git a/inflate.c b/inflate.c
> index 5b68314..75353e2 100644
> --- a/inflate.c
> +++ b/inflate.c
> @@ -589,7 +589,8 @@ int bl, bd;             /* number of bits 
> decoded by tl[] and td[] */
>        do {
>          n -= (e = (e = WSIZE - ((d &= WSIZE-1) > w ? d : w)) 
> > n ? n : e);  #if !defined(NOMEMCPY) && !defined(DEBUG)
> -        if (d < w && w - d >= e)
> +        unsigned int delta = w > d ? w - d : d - w;
> +        if (delta >= e)
>          {
>            memcpy(slide + w, slide + d, e);
>            w += e;
> --
> 1.6.6.511.gf46c4
> 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]