From 77bde2ea5452ebf2662cda95520db2b0bc95747a Mon Sep 17 00:00:00 2001 From: Zeex Date: Sat, 25 Jan 2014 19:22:40 +0700 Subject: [PATCH] More optimal array growth factor http://stackoverflow.com/questions/1100311/what-is-the-ideal-growth-rate-for-a-dynamically-allocated-array --- source/compiler/sclist.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/compiler/sclist.c b/source/compiler/sclist.c index 4ca4ddc..25ae6e8 100644 --- a/source/compiler/sclist.c +++ b/source/compiler/sclist.c @@ -155,10 +155,10 @@ static stringlist *insert_string(stringlist *list,char *string) break; if (i==list->size) { /* double the size of the list */ - newsize=list->size*2; + newsize=list->size+list->size/2; if ((newstrings=realloc(list->strings,newsize*sizeof(char*)))==NULL) error(103); /* insufficient memory (fatal error) */ - memset(newstrings+list->size,0,list->size*sizeof(char*)); + memset(newstrings+list->size,0,list->size/2*sizeof(char*)); list->strings=newstrings; list->size=newsize; } /* if */