zsh-workers
 help / color / mirror / code / Atom feed
From: Daniel Shahaf <d.s@daniel.shahaf.name>
To: Sebastian Gniazdowski <psprint@fastmail.com>
Cc: zsh-workers@zsh.org
Subject: Re: [PATCH] Mild setarrvalue() optimization
Date: Tue, 8 Nov 2016 15:46:40 +0000	[thread overview]
Message-ID: <20161108154640.GB21983@fujitsu.shahaf.local2> (raw)
In-Reply-To: <1478600824.1774565.780940761.5A517B9E@webmail.messagingengine.com>

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


      reply	other threads:[~2016-11-08 15:49 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-08 10:27 Sebastian Gniazdowski
2016-11-08 15:46 ` Daniel Shahaf [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20161108154640.GB21983@fujitsu.shahaf.local2 \
    --to=d.s@daniel.shahaf.name \
    --cc=psprint@fastmail.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).