ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/malloc.c
(Generate patch)

Comparing ray/src/common/malloc.c (file contents):
Revision 1.4 by greg, Wed Sep 26 08:26:11 1990 UTC vs.
Revision 1.5 by greg, Wed Sep 26 13:46:52 1990 UTC

# Line 172 | Line 172 | realloc(op, n)                 /* reallocate memory using malloc() *
172   char    *op;
173   unsigned        n;
174   {
175        extern char     *memcpy();
175          register char   *p;
176          register unsigned       on;
177  
178 <        free(op);                       /* free it first */
179 <        p = malloc(n);                  /* p==op if same bucket */
180 <        if (p == NULL)
181 <                return(NULL);
182 <        if (p != op)                    /* different bucket, do copy */
178 >        if (op != NULL)
179 >                on = 1 << ((M_HEAD *)op-1)->bucket;
180 >        else
181 >                on = 0;
182 >        if (n <= on && n > on>>1)
183 >                return(op);             /* same bucket */
184 >        p = malloc(n);
185 >        if (p != NULL)
186   #ifdef  BSD
187                  bcopy(op, p, n>on ? on : n);
188   #else
189                  (void)memcpy(p, op, n>on ? on : n);
190   #endif
191 +        free(op);
192          return(p);
193   }
194  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines