Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

PATCH: Avoid accumulating eprog on heap for every file in qualsheval



---

Something along these lines perhaps? I can't quite reproduce your
original big difference in memory usage, but if you could check if this
a) reduces peak memory usage and b) doesn't increase runtime, that would
be nice.

 Src/exec.c  | 21 +++++++++++++++++----
 Src/glob.c  |  3 ++-
 Src/parse.c |  4 ++--
 3 files changed, 21 insertions(+), 7 deletions(-)

diff --git a/Src/exec.c b/Src/exec.c
index 1fe9932c00..b06239c580 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -283,9 +283,8 @@ static struct builtin commandbn =
 
 /* parse string into a list */
 
-/**/
-mod_export Eprog
-parse_string(char *s, int reset_lineno)
+static Eprog
+parse_string_internal(char *s, int reset_lineno, int heap)
 {
     Eprog p;
     zlong oldlineno;
@@ -296,7 +295,7 @@ parse_string(char *s, int reset_lineno)
     oldlineno = lineno;
     if (reset_lineno)
 	lineno = 1;
-    p = parse_list();
+    p = parse_list(heap);
     lineno = oldlineno;
     if (tok == LEXERR && !lastval)
 	lastval = 1;
@@ -306,6 +305,20 @@ parse_string(char *s, int reset_lineno)
     return p;
 }
 
+/**/
+mod_export Eprog
+parse_ztring(char *s, int reset_lineno)
+{
+    return parse_string_internal(s, reset_lineno, 0);
+}
+
+/**/
+mod_export Eprog
+parse_string(char *s, int reset_lineno)
+{
+    return parse_string_internal(s, reset_lineno, 1);
+}
+
 /**/
 #ifdef HAVE_GETRLIMIT
 
diff --git a/Src/glob.c b/Src/glob.c
index edbb74fa4c..7b7d3366b2 100644
--- a/Src/glob.c
+++ b/Src/glob.c
@@ -3975,7 +3975,7 @@ qualsheval(char *name, UNUSED(struct stat *buf), UNUSED(off_t days), char *str)
 {
     Eprog prog;
 
-    if ((prog = parse_string(str, 0))) {
+    if ((prog = parse_ztring(str, 0))) {
 	int ef = errflag, lv = lastval, ret;
 	int cshglob = badcshglob;
 
@@ -3985,6 +3985,7 @@ qualsheval(char *name, UNUSED(struct stat *buf), UNUSED(off_t days), char *str)
 	badcshglob = 0;
 
 	execode(prog, 1, 0, "globqual");
+	freeeprog(prog);
 
 	if ((ret = lastval))
 	    badcshglob |= cshglob;
diff --git a/Src/parse.c b/Src/parse.c
index 6d336bfa7b..5fab170dd3 100644
--- a/Src/parse.c
+++ b/Src/parse.c
@@ -694,7 +694,7 @@ par_event(int endtok)
 
 /**/
 mod_export Eprog
-parse_list(void)
+parse_list(int heap)
 {
     int c = 0;
 
@@ -708,7 +708,7 @@ parse_list(void)
 	yyerror(0);
 	return NULL;
     }
-    return bld_eprog(1);
+    return bld_eprog(heap);
 }
 
 /*
-- 
2.38.1





Messages sorted by: Reverse Date, Date, Thread, Author