Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: [PATCH] Mild setarrvalue() optimization
- X-seq: zsh-workers 39874
- From: Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx>
- To: Sebastian Gniazdowski <psprint@xxxxxxxxxxxx>
- Subject: Re: [PATCH] Mild setarrvalue() optimization
- Date: Tue, 8 Nov 2016 15:46:40 +0000
- Cc: zsh-workers@xxxxxxx
- Dkim-signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= daniel.shahaf.name; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc:x-sasl-enc; s=mesmtp; bh=bVQwJNxPefr+DxH ObsEtgsOO8Rc=; b=QInFw7Admgt98yc9a7y9izvr/Hjpa0ug7RS/c05y2ATmGYq /QKO+tUEtYhdXWFA+QxqAWxfL3y7TRz0+hra7jsRABVNPbTcfVxAZUQF9i/1ft2X 6Cl3GjY5WNHfrmHlczcNxuoi3s3DVLC1bQfPTEkudLpdV94GPND7ZrI/Oqyg=
- Dkim-signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc:x-sasl-enc; s=smtpout; bh=bVQwJNxPefr+Dx HObsEtgsOO8Rc=; b=MLVhB3t+YAcEdhz5EWn/jTQXh6syY0/q4+GiYfsA02RvXO 2ytNpLMU5cqbc0GvIncMlpe6RkeiJws10LGQdD5oM1jyY1zHk6xnH4Fa2cIuXCvB NYAmZuK+Q3lqLGLRjcW5Fivs7PMAsv8WVH5Vmb7jd2TJ8pXxjNJYmjwF3RuvE=
- In-reply-to: <1478600824.1774565.780940761.5A517B9E@webmail.messagingengine.com>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <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;
}
Messages sorted by:
Reverse Date,
Date,
Thread,
Author