1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-09-02 10:01:11 +02:00

make the parser use real memory for the ecbuf to avoid having hrealloc() throw away lots of memory (13576)

This commit is contained in:
Sven Wischnowsky 2001-03-06 13:00:40 +00:00
parent c8f2e51007
commit 684c9eebe5
3 changed files with 25 additions and 7 deletions

View file

@ -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

View file

@ -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;

View file

@ -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;
}