diff options
-rw-r--r-- | ChangeLog | 3 | ||||
-rw-r--r-- | Src/lex.c | 3 | ||||
-rw-r--r-- | Src/parse.c | 26 |
3 files changed, 25 insertions, 7 deletions
diff --git a/ChangeLog b/ChangeLog index d96af1d86..1ca512b8f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2001-03-06 Sven Wischnowsky <wischnow@zsh.org> + * 13576: Src/lex.c, Src/parse.c: make the parser use real memory + for the ecbuf to avoid having hrealloc() throw away lots of memory + * 13575: Src/Zle/compmatch.c: another fix for completion matching, CLF_MISS in the wrong cline struct diff --git a/Src/lex.c b/Src/lex.c index 322bb9abe..de58ade7a 100644 --- a/Src/lex.c +++ b/Src/lex.c @@ -270,6 +270,7 @@ lexsave(void) inredir = 0; hdocs = NULL; histactive = 0; + ecbuf = NULL; ls->next = lstack; lstack = ls; @@ -318,6 +319,8 @@ lexrestore(void) hwbegin = lstack->hwbegin; hwend = lstack->hwend; addtoline = lstack->addtoline; + if (ecbuf) + zfree(ecbuf, eclen); eclen = lstack->eclen; ecused = lstack->ecused; ecnpats = lstack->ecnpats; 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; } |