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

Re: [PATCH] Mild setarrvalue() optimization



Sebastian Gniazdowski wrote on Tue, Nov 08, 2016 at 02:27:04 -0800:
> there's freearray() at end of setarrvalue(). It can be replaced with
> free() if ownership of all strings will be given away:

I see this has been applied.

s/calloc/malloc/ should save a few more milliseconds.

Also reduce code duplication.

Cheers,

Daniel

diff --git a/Src/params.c b/Src/params.c
index 19a8c29..9f449c5 100644
--- a/Src/params.c
+++ b/Src/params.c
@@ -2651,8 +2651,8 @@ setarrvalue(Value v, char **val)
 	if (v->end <= pre_assignment_length)
 	    post_assignment_length += pre_assignment_length - v->end + 1;
 
-	p = new = (char **) zshcalloc(sizeof(char *)
-		                      * (post_assignment_length + 1));
+	p = new = (char **) zalloc(sizeof(char *)
+		                   * (post_assignment_length + 1));
 
 	for (i = 0; i < v->start; i++)
 	    *p++ = i < pre_assignment_length ? ztrdup(*q++) : ztrdup("");
diff --git a/Src/mem.c b/Src/mem.c
index 8c7eb80..0ac4009 100644
--- a/Src/mem.c
+++ b/Src/mem.c
@@ -976,18 +976,8 @@ zalloc(size_t size)
 mod_export void *
 zshcalloc(size_t size)
 {
-    void *ptr;
-
-    if (!size)
-	size = 1;
-    queue_signals();
-    if (!(ptr = (void *) malloc(size))) {
-	zerr("fatal error: out of memory");
-	exit(1);
-    }
-    unqueue_signals();
+    void *ptr = zalloc(size);
     memset(ptr, 0, size);
-
     return ptr;
 }
 



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