From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7084 invoked by alias); 10 Nov 2016 12:32:09 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 39905 Received: (qmail 23930 invoked from network); 10 Nov 2016 12:32:09 -0000 X-Qmail-Scanner-Diagnostics: from mailout3.w1.samsung.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(210.118.77.13):SA:0(-2.9/5.0):. Processed in 0.555 secs); 10 Nov 2016 12:32:09 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=RP_MATCHES_RCVD autolearn=unavailable autolearn_force=no version=3.4.1 X-Envelope-From: p.stephenson@samsung.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: none (ns1.primenet.com.au: domain at samsung.com does not designate permitted sender hosts) X-AuditID: cbfec7f1-f79f46d0000008eb-84-582468c01400 Date: Thu, 10 Nov 2016 12:31:56 +0000 From: Peter Stephenson To: zsh-workers@zsh.org Subject: Re: Callgrind run Message-id: <20161110123156.1d1699ec@pwslap01u.europe.root.pri> In-reply-to: <1478774232.2371010.783342705.69C81F52@webmail.messagingengine.com> Organization: Samsung Cambridge Solution Centre X-Mailer: Claws Mail 3.7.9 (GTK+ 2.22.0; i386-redhat-linux-gnu) MIME-version: 1.0 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrHIsWRmVeSWpSXmKPExsWy7djPc7oHMlQiDA6/k7E42PyQyYHRY9XB D0wBjFFcNimpOZllqUX6dglcGZ/bWpkL1qlU3PncwtLAuFG6i5GTQ0LAROLg7CvMELaYxIV7 69m6GLk4hASWMkosP93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l1q6ZBpbgF9CX uPr3ExPEffYSM6+cYYRoFpT4Mfke2FBmAS2JzduaWCFseYnNa94yQ1yqLnHj7m72CYzCs5C0 zELSMgtJywJG5lWMIqmlxbnpucVGesWJucWleel6yfm5mxiBcbTt2M8tOxi73gUfYhTgYFTi 4e3QVI4QYk0sK67MPcQowcGsJMJ7OE0lQog3JbGyKrUoP76oNCe1+BCjKTBkJjJLiSbnA2M8 ryTe0MTQ3NLQyNjCwtzISEmcd+qHK+FCAumJJanZqakFqUUwfUwcnFINjCuNSp2DZ3f7OWxd X/puaVs2g9wd809P9izkNWJfcpNhtfzz14rOq7YVFP+pCrQKW3LkzPOt2qdV1Pgnbz9tzJy+ 5UqRfrOEhb3mTm+XwhkJzwyPCi/89FpVpqOK4e+9ys8nL3vyVOi2TOIROPQ0aTJLw2KlZWe8 rI9w8PQ/NZRmbpeoSJTYpcRSnJFoqMVcVJwIAAsurnS5AgAA X-MTR: 20000000000000000@CPGS X-CMS-MailID: 20161110123200eucas1p218cede1cced755a0b75b22cb667938e6 X-Msg-Generator: CA X-Sender-IP: 182.198.249.180 X-Local-Sender: =?UTF-8?B?UGV0ZXIgU3RlcGhlbnNvbhtTQ1NDLURhdGEgUGxhbmUb?= =?UTF-8?B?7IK87ISx7KCE7J6QG1ByaW5jaXBhbCBFbmdpbmVlciwgU29mdHdhcmU=?= X-Global-Sender: =?UTF-8?B?UGV0ZXIgU3RlcGhlbnNvbhtTQ1NDLURhdGEgUGxhbmUbU2Ft?= =?UTF-8?B?c3VuZyBFbGVjdHJvbmljcxtQcmluY2lwYWwgRW5naW5lZXIsIFNvZnR3YXJl?= X-Sender-Code: =?UTF-8?B?QzEwG0VIURtDMTBDRDA1Q0QwNTAwNTg=?= CMS-TYPE: 201P X-HopCount: 7 X-CMS-RootMailID: 20161110103845epcas3p3e7cabeffae723219daafa8d3e6b32f12 X-RootMTR: 20161110103845epcas3p3e7cabeffae723219daafa8d3e6b32f12 References: <1478774232.2371010.783342705.69C81F52@webmail.messagingengine.com> On Thu, 10 Nov 2016 02:37:12 -0800 Sebastian Gniazdowski wrote: > Seems that Zsh execution could be greatly optimized if functions: > remnulargs, untokenize, haswilds could be optimized. Not sure if the > results are reasonable, as haswilds just iterates over a string and does > quite basic switch. The other two functions have nested loops, so they > look more likely as being time consuming. Maybe the nested loop can be > changed to something else? The nested loops aren't "real" nested loops; the inner loop runs to completion and then breaks if the outer loop detects a condition that needs handling. To do a good job optimising here, we really need state information outside the functions --- in an experiment with my start up files, only 16% of calls to untokenize() actually had any effect. But recording the state generally is a very big change. Some possible optimisations are along the following lines, although a bit of care it's needed as it's not necessarily the case on all architectures that the bit test used by itok() is necessarily faster than the range test the following replaces it with. It did seem faster on this fairly standard Intel CPU. I probably won't be committing this. diff --git a/Src/exec.c b/Src/exec.c index a01a633..a6b01a6 100644 --- a/Src/exec.c +++ b/Src/exec.c @@ -1953,26 +1953,24 @@ makecline(LinkList list) mod_export void untokenize(char *s) { - if (*s) { + if (*s) { /* "" may be a const string. Ick. */ int c; - while ((c = *s++)) - if (itok(c)) { + while ((c = *s++)) { + if (c >= FIRST_TOK && c <= LAST_TOK) { char *p = s - 1; if (c != Nularg) - *p++ = ztokens[c - Pound]; + *p++ = ztoken_to_char[STOUC(c)]; while ((c = *s++)) { - if (itok(c)) { - if (c != Nularg) - *p++ = ztokens[c - Pound]; - } else - *p++ = c; + if (c != Nularg) + *p++ = ztoken_to_char[STOUC(c)]; } *p = '\0'; break; } + } } } diff --git a/Src/glob.c b/Src/glob.c index 50f6dce..4d3fc51 100644 --- a/Src/glob.c +++ b/Src/glob.c @@ -3570,7 +3570,7 @@ remnulargs(char *s) if (*s) { char *o = s, c; - while ((c = *s++)) + while ((c = *s++)) { if (c == Bnullkeep) { /* * An active backslash that needs to be turned back into @@ -3579,7 +3579,7 @@ remnulargs(char *s) * pattern matching. */ continue; - } else if (inull(c)) { + } else if (c >= FIRST_NULL && c <= LAST_NULL) { char *t = s - 1; while ((c = *s++)) { @@ -3595,6 +3595,7 @@ remnulargs(char *s) } break; } + } } } diff --git a/Src/lex.c b/Src/lex.c index 8896128..bfd6b11 100644 --- a/Src/lex.c +++ b/Src/lex.c @@ -37,6 +37,18 @@ /**/ mod_export char ztokens[] = "#$^*(())$=|{}[]`<>>?~`,-!'\"\\\\"; +/* + * Map a possibly tokenized unsigned char to a normal unsigned + * char, for use in untokenize(). + * + * Tokens that need untokenizing (everything in ztokens except Nularg) + * map to a different character, everything else maps to itself. + * In particular, metafied characters are passed through unchanged + * (effectively escaping tokens) and do not need special handling. + */ +/**/ +mod_export char ztoken_to_char[256]; + /* parts of the current token */ /**/ diff --git a/Src/utils.c b/Src/utils.c index 3d535b8..9fa8a97 100644 --- a/Src/utils.c +++ b/Src/utils.c @@ -4012,6 +4012,18 @@ inittyptab(void) for (s = PATCHARS; *s; s++) typtab[STOUC(*s)] |= IPATTERN; + for (t0 = 0; t0 < 256; t0++) + { + if (itok(t0) && (char)t0 != Nularg) + { + ztoken_to_char[t0] = ztokens[t0 - STOUC(Pound)]; + } + else + { + ztoken_to_char[t0] = (char)t0; + } + } + unqueue_signals(); } diff --git a/Src/zsh.h b/Src/zsh.h index a5d4455..5065a54 100644 --- a/Src/zsh.h +++ b/Src/zsh.h @@ -170,6 +170,7 @@ struct mathfunc { * These should match the characters in ztokens, defined in lex.c */ #define Pound ((char) 0x84) +#define FIRST_TOK Pound #define String ((char) 0x85) #define Hat ((char) 0x86) #define Star ((char) 0x87) @@ -204,6 +205,7 @@ struct mathfunc { * and backslashes. */ #define Snull ((char) 0x9d) +#define FIRST_NULL Snull #define Dnull ((char) 0x9e) #define Bnull ((char) 0x9f) /* @@ -217,6 +219,8 @@ struct mathfunc { * is used to initialise the IMETA type in inittyptab(). */ #define Nularg ((char) 0xa1) +#define LAST_TOK Nularg +#define LAST_NULL Nularg /* * Take care to update the use of IMETA appropriately when adding