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

Comparing ray/src/util/rcollate.c (file contents):
Revision 2.7 by greg, Mon Nov 18 22:02:12 2013 UTC vs.
Revision 2.8 by greg, Fri Feb 21 13:49:00 2014 UTC

# Line 103 | Line 103 | load_file(MEMLOAD *mp, FILE *fp)
103   static int
104   load_stream(MEMLOAD *mp, FILE *fp)
105   {
106 +        size_t  alloced = 0;
107          char    buf[8192];
108          size_t  nr;
109  
# Line 114 | Line 115 | load_stream(MEMLOAD *mp, FILE *fp)
115          if (fp == NULL)
116                  return(-1);
117          while ((nr = fread(buf, 1, sizeof(buf), fp)) > 0) {
118 <                if (!mp->len)
118 >                if (!alloced)
119                          mp->base = malloc(nr);
120 <                else
121 <                        mp->base = realloc(mp->base, mp->len+nr);
120 >                else if (mp->len+nr > alloced)
121 >                        mp->base = realloc(mp->base,
122 >                                alloced = alloced*(2+(nr==sizeof(buf)))/2+nr);
123                  if (mp->base == NULL)
124                          return(-1);
125                  memcpy((char *)mp->base + mp->len, buf, nr);
# Line 127 | Line 129 | load_stream(MEMLOAD *mp, FILE *fp)
129                  free_load(mp);
130                  return(-1);
131          }
132 +        if (alloced > mp->len*5/4)      /* don't waste too much space */
133 +                mp->base = realloc(mp->base, mp->len);
134          return(mp->len > 0);
135   }
136  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines