Fixed staging buffers reallocating on every operation (bug 3820, r=fyren+fyren).
authorDavid Anderson <dvander@alliedmods.net>
Fri Jul 02 18:16:50 2010 -0700 (2010-07-02)
changeset 3069b2656266b6d9
parent 3068 08b3a3e69cb1
child 3070 dc361050274d
Fixed staging buffers reallocating on every operation (bug 3820, r=fyren+fyren).
sourcepawn/compiler/sc7.c
     1.1 --- a/sourcepawn/compiler/sc7.c	Fri Jul 02 18:16:15 2010 -0700
     1.2 +++ b/sourcepawn/compiler/sc7.c	Fri Jul 02 18:16:50 2010 -0700
     1.3 @@ -82,25 +82,25 @@
     1.4  static int pipemax=0;   /* current size of the stage pipe, a second staging buffer */
     1.5  static int pipeidx=0;
     1.6  
     1.7 -#define CHECK_STGBUFFER(index) if ((int)(index)>=stgmax)  grow_stgbuffer(&stgbuf, stgmax, (index)+1)
     1.8 -#define CHECK_STGPIPE(index)   if ((int)(index)>=pipemax) grow_stgbuffer(&stgpipe, pipemax, (index)+1)
     1.9 +#define CHECK_STGBUFFER(index) if ((int)(index)>=stgmax)  grow_stgbuffer(&stgbuf, &stgmax, (index)+1)
    1.10 +#define CHECK_STGPIPE(index)   if ((int)(index)>=pipemax) grow_stgbuffer(&stgpipe, &pipemax, (index)+1)
    1.11  
    1.12 -static void grow_stgbuffer(char **buffer, int curmax, int requiredsize)
    1.13 +static void grow_stgbuffer(char **buffer, int *curmax, int requiredsize)
    1.14  {
    1.15    char *p;
    1.16    int clear= (*buffer==NULL); /* if previously none, empty buffer explicitly */
    1.17  
    1.18 -  assert(curmax<requiredsize);
    1.19 +  assert(*curmax<requiredsize);
    1.20    /* if the staging buffer (holding intermediate code for one line) grows
    1.21     * over a few kBytes, there is probably a run-away expression
    1.22     */
    1.23    if (requiredsize>sSTG_MAX)
    1.24      error(102,"staging buffer");    /* staging buffer overflow (fatal error) */
    1.25 -  curmax=requiredsize+sSTG_GROW;
    1.26 +  *curmax=requiredsize+sSTG_GROW;
    1.27    if (*buffer!=NULL)
    1.28 -    p=(char *)realloc(*buffer,curmax*sizeof(char));
    1.29 +    p=(char *)realloc(*buffer,*curmax*sizeof(char));
    1.30    else
    1.31 -    p=(char *)malloc(curmax*sizeof(char));
    1.32 +    p=(char *)malloc(*curmax*sizeof(char));
    1.33    if (p==NULL)
    1.34      error(102,"staging buffer");    /* staging buffer overflow (fatal error) */
    1.35    *buffer=p;