zsh-workers
 help / color / mirror / code / Atom feed
From: Daniel Shahaf <d.s@daniel.shahaf.name>
To: Zsh hackers list <zsh-workers@zsh.org>
Cc: Sebastian Gniazdowski <psprint@fastmail.com>
Subject: Re: Possible huge setarrvalue optimization
Date: Sat, 24 Dec 2016 17:19:36 +0000	[thread overview]
Message-ID: <20161224171936.GA19748@fujitsu.shahaf.local2> (raw)
In-Reply-To: <CAH+w=7YsEm=3WF_fs5Zyv9n+z7QOtwyOqss6Yv9Vpvtdqz_eiA@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1812 bytes --]

Bart Schaefer wrote on Sun, Nov 20, 2016 at 09:41:48 -0800:
> This and the proposed getstr optimization both make me nervous.  I know
> Sebastian is anxious to have them appear in the next release, but it feels
> and if we should have more time using them in dev branches.

I assume we can go ahead now.

Here's a revised patch based on my review upthread:

diff --git a/Src/params.c b/Src/params.c
index 82554a7..c4dad8f 100644
--- a/Src/params.c
+++ b/Src/params.c
@@ -2708,6 +2708,23 @@ setarrvalue(Value v, char **val)
 	    post_assignment_length += pre_assignment_length - v->end;
 	}
 
+	if (pre_assignment_length == post_assignment_length
+	    && v->pm->gsu.a->setfn == arrsetfn
+	    /* ... and isn't something that arrsetfn() treats specially */
+	    && 0 == (v->pm->node.flags & (PM_SPECIAL|PM_UNIQUE))
+	    && NULL == v->pm->ename)
+    {
+	/* v->start is 0-based */
+	p = old + v->start;
+	for (r = val; *r;) {
+	    /* Free previous string */
+	    zsfree(*p);
+	    /* Give away ownership of the string */
+	    *p++ = *r++;
+	}
+    }
+	else
+    {
 	p = new = (char **) zalloc(sizeof(char *)
 		                   * (post_assignment_length + 1));
 
@@ -2726,6 +2743,7 @@ setarrvalue(Value v, char **val)
 	       post_assignment_length, (unsigned long)(p - new));
 
 	v->pm->gsu.a->setfn(v->pm, new);
+    }
 
         /* Ownership of all strings has been
          * given away, can plainly free */
@@ -3485,6 +3503,8 @@ arrsetfn(Param pm, char **x)
     /* Arrays tied to colon-arrays may need to fix the environment */
     if (pm->ename && x)
 	arrfixenv(pm->ename, x);
+    /* If you extend this function, update the list of conditions in
+     * setarrvalue(). */
 }
 
 /* Function to get value of an association parameter */

If no objections, I'll reindent and push.

Cheers,

Daniel

[-- Attachment #2: 0001-39996-Optimize-setarrvalue.patch --]
[-- Type: text/x-diff, Size: 1698 bytes --]

>From b4870d1cab9db235860adcadd821069b2e2162e9 Mon Sep 17 00:00:00 2001
From: Sebastian Gniazdowski <psprint@fastmail.com>
Date: Tue, 22 Nov 2016 09:26:46 +0000
Subject: [PATCH] AFTER RELEASE: 39996: Optimize setarrvalue().

---
 Src/params.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/Src/params.c b/Src/params.c
index 82554a7..c4dad8f 100644
--- a/Src/params.c
+++ b/Src/params.c
@@ -2708,6 +2708,23 @@ setarrvalue(Value v, char **val)
 	    post_assignment_length += pre_assignment_length - v->end;
 	}
 
+	if (pre_assignment_length == post_assignment_length
+	    && v->pm->gsu.a->setfn == arrsetfn
+	    /* ... and isn't something that arrsetfn() treats specially */
+	    && 0 == (v->pm->node.flags & (PM_SPECIAL|PM_UNIQUE))
+	    && NULL == v->pm->ename)
+    {
+	/* v->start is 0-based */
+	p = old + v->start;
+	for (r = val; *r;) {
+	    /* Free previous string */
+	    zsfree(*p);
+	    /* Give away ownership of the string */
+	    *p++ = *r++;
+	}
+    }
+	else
+    {
 	p = new = (char **) zalloc(sizeof(char *)
 		                   * (post_assignment_length + 1));
 
@@ -2726,6 +2743,7 @@ setarrvalue(Value v, char **val)
 	       post_assignment_length, (unsigned long)(p - new));
 
 	v->pm->gsu.a->setfn(v->pm, new);
+    }
 
         /* Ownership of all strings has been
          * given away, can plainly free */
@@ -3485,6 +3503,8 @@ arrsetfn(Param pm, char **x)
     /* Arrays tied to colon-arrays may need to fix the environment */
     if (pm->ename && x)
 	arrfixenv(pm->ename, x);
+    /* If you extend this function, update the list of conditions in
+     * setarrvalue(). */
 }
 
 /* Function to get value of an association parameter */

  parent reply	other threads:[~2016-12-24 17:22 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-18  6:17 Sebastian Gniazdowski
2016-11-18  7:09 ` Sebastian Gniazdowski
2016-11-18  9:32 ` Sebastian Gniazdowski
2016-11-18 12:20   ` Sebastian Gniazdowski
2016-11-20 11:46     ` Daniel Shahaf
2016-11-20 17:41       ` Bart Schaefer
2016-11-20 20:54         ` Sebastian Gniazdowski
2016-11-20 21:19         ` Peter Stephenson
2016-12-24 17:19         ` Daniel Shahaf [this message]
2017-01-04 18:31           ` Sebastian Gniazdowski
2017-01-05  4:13             ` Daniel Shahaf
2017-01-05 13:32               ` Sebastian Gniazdowski
2017-01-05 15:47                 ` Daniel Shahaf

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=20161224171936.GA19748@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).