about summary refs log tree commit diff
path: root/Src/parse.c
diff options
context:
space:
mode:
authorSven Wischnowsky <wischnow@users.sourceforge.net>2001-03-06 13:00:40 +0000
committerSven Wischnowsky <wischnow@users.sourceforge.net>2001-03-06 13:00:40 +0000
commit684c9eebe52be2f8e7ef05df794f5213b5858555 (patch)
tree3e7fb3f9ee151f1a961fea0b53117ff75510b2a4 /Src/parse.c
parentc8f2e51007b7e3fd4bf581ca92b4ff13e7aae8ed (diff)
downloadzsh-684c9eebe52be2f8e7ef05df794f5213b5858555.tar.gz
zsh-684c9eebe52be2f8e7ef05df794f5213b5858555.tar.xz
zsh-684c9eebe52be2f8e7ef05df794f5213b5858555.zip
make the parser use real memory for the ecbuf to avoid having hrealloc() throw away lots of memory (13576)
Diffstat (limited to 'Src/parse.c')
-rw-r--r--Src/parse.c26
1 files changed, 19 insertions, 7 deletions
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;
 }