From 684c9eebe52be2f8e7ef05df794f5213b5858555 Mon Sep 17 00:00:00 2001 From: Sven Wischnowsky Date: Tue, 6 Mar 2001 13:00:40 +0000 Subject: make the parser use real memory for the ecbuf to avoid having hrealloc() throw away lots of memory (13576) --- Src/parse.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) (limited to 'Src/parse.c') diff --git a/Src/parse.c b/Src/parse.c index 330ebbfb5..5f0938546 100644 --- a/Src/parse.c +++ b/Src/parse.c @@ -235,6 +235,11 @@ Eccstr ecstrs; /**/ int ecsoffs, ecssub, ecnfunc; +#define EC_INIT_SIZE 256 +#define EC_DOUBLE_THRESHOLD 32768 +#define EC_INCREMENT 1024 + + /* Adjust pointers in here-doc structs. */ static void @@ -255,10 +260,11 @@ ecispace(int p, int n) int m; if ((eclen - ecused) < n) { - int a = (n > 256 ? n : 256); + int a = (eclen < EC_DOUBLE_THRESHOLD ? eclen : EC_INCREMENT); - ecbuf = (Wordcode) hrealloc((char *) ecbuf, eclen * sizeof(wordcode), - (eclen + a) * sizeof(wordcode)); + if (n > a) a = n; + + ecbuf = (Wordcode) zrealloc((char *) ecbuf, (eclen + a) * sizeof(wordcode)); eclen += a; } if ((m = ecused - p) > 0) @@ -273,9 +279,10 @@ static int ecadd(wordcode c) { if ((eclen - ecused) < 1) { - ecbuf = (Wordcode) hrealloc((char *) ecbuf, eclen * sizeof(wordcode), - (eclen + 256) * sizeof(wordcode)); - eclen += 256; + int a = (eclen < EC_DOUBLE_THRESHOLD ? eclen : EC_INCREMENT); + + ecbuf = (Wordcode) zrealloc((char *) ecbuf, (eclen + a) * sizeof(wordcode)); + eclen += a; } ecbuf[ecused] = c; ecused++; @@ -360,7 +367,9 @@ ecstr(char *s) static void init_parse(void) { - ecbuf = (Wordcode) zhalloc((eclen = 256) * sizeof(wordcode)); + if (ecbuf) zfree(ecbuf, eclen); + + ecbuf = (Wordcode) zalloc((eclen = EC_INIT_SIZE) * sizeof(wordcode)); ecused = 0; ecstrs = NULL; ecsoffs = ecnpats = 0; @@ -398,6 +407,9 @@ bld_eprog(void) l = strlen(p->str) + 1; memcpy(q, p->str, l); } + zfree(ecbuf, eclen); + ecbuf = NULL; + return ret; } -- cgit 1.4.1