Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: [PATCH] Optimization for mb_metastrlenend()
- X-seq: zsh-workers 39826
- From: Sebastian Gniazdowski <psprint@xxxxxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: Re: [PATCH] Optimization for mb_metastrlenend()
- Date: Thu, 03 Nov 2016 12:47:01 -0700
- Dkim-signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=fastmail.com; h= content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc; s=mesmtp; bh=T/Y8YBU59G59txJzX67m567PnG Y=; b=kLZc7DubPdRAKxRhkvLc9hnb7sXXdfKOpUCGvHWVomYDSamWjegJ/TKzH1 489/za8Oh3QdQRDMn44WMU6+i1rN2bhWb+RW29G8glq3R/LWgG0qZqsRVUKRcBec QXd7I81i2Tcwe5/+FkPLmH07cj1evqTzzy7pNt2SXj5srxyp8=
- Dkim-signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-sender:x-me-sender:x-sasl-enc; s=smtpout; bh=T/ Y8YBU59G59txJzX67m567PnGY=; b=GMRjq2/pYUzJmGkOP1QrZ2IHcc/hK947fm VupBnvlkeGKIXRlHF43BM+UfKZ+c5cvYZIuclRGFtHtoT6SD65JgAhq3++Piq4rr OZmYwcGnW+klWmDuzWPMKL0LkSUMMV/ruWb/k4YXRaaFm31qlzjCAdWlMSnEhFXX iejpVtbRY=
- In-reply-to: <1478202252.540329.776653241.444797D3@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: <1478202252.540329.776653241.444797D3@webmail.messagingengine.com>
The missing files
--
Sebastian Gniazdowski
psprint@xxxxxxxxxxxx
diff --git a/Src/utils.c b/Src/utils.c
index db43529..5bc9ef4 100644
--- a/Src/utils.c
+++ b/Src/utils.c
@@ -5323,7 +5323,7 @@ mb_metastrlenend(char *ptr, int width, char *eptr)
char inchar, *laststart;
size_t ret;
wchar_t wc;
- int num, num_in_char;
+ int num, num_in_char, complete;
if (!isset(MULTIBYTE))
return ztrlen(ptr);
@@ -5331,6 +5331,7 @@ mb_metastrlenend(char *ptr, int width, char *eptr)
laststart = ptr;
ret = MB_INVALID;
num = num_in_char = 0;
+ complete = 1;
memset(&mb_shiftstate, 0, sizeof(mb_shiftstate));
while (*ptr && !(eptr && ptr >= eptr)) {
@@ -5339,6 +5340,14 @@ mb_metastrlenend(char *ptr, int width, char *eptr)
else
inchar = *ptr;
ptr++;
+
+ if ( complete && ( inchar >= 0 && inchar <= 0x7f ) ) {
+ num ++;
+ laststart = ptr;
+ num_in_char = 0;
+ continue;
+ }
+
ret = mbrtowc(&wc, &inchar, 1, &mb_shiftstate);
if (ret == MB_INCOMPLETE) {
@@ -5358,6 +5367,7 @@ mb_metastrlenend(char *ptr, int width, char *eptr)
* so we don't count characters twice.
*/
num_in_char++;
+ complete = 0;
} else {
if (ret == MB_INVALID) {
/* Reset, treat as single character */
@@ -5378,8 +5388,10 @@ mb_metastrlenend(char *ptr, int width, char *eptr)
}
} else
num++;
+
laststart = ptr;
num_in_char = 0;
+ complete = 1;
}
}
git clone https://github.com/psprint/history-search-multi-word.git
cd test; ./parse.zsh ./to-parse.zsh
823 lines parsed with modified, optimized zsh-syntax-highlighting code
After optimization, minimum obtainable time:
Running time: 2.0280520000
num calls time self name
-----------------------------------------------------------------------------------
1) 1 2027,49 2027,49 100,00% 1898,46 1898,46 93,63% -hsmw-highlight-process
2) 754 109,36 0,15 5,39% 109,36 0,15 5,39% -hsmw-highlight-main-type
3) 395 11,57 0,03 0,57% 11,57 0,03 0,57% -hsmw-highlight-check-path
4) 22 5,78 0,26 0,28% 5,78 0,26 0,28% -hsmw-highlight-string
5) 6 2,33 0,39 0,11% 2,33 0,39 0,11% -hsmw-highlight-dollar-string
6) 1 0,07 0,07 0,00% 0,07 0,07 0,00% -hsmw-highlight-fill-option-variables
7) 1 0,01 0,01 0,00% 0,01 0,01 0,00% -hsmw-highlight-init
Before optimization, minimum obtainable time:
Running time: 2.2383990000
num calls time self name
-----------------------------------------------------------------------------------
1) 1 2237,79 2237,79 100,00% 2104,55 2104,55 94,04% -hsmw-highlight-process
2) 754 113,73 0,15 5,08% 113,73 0,15 5,08% -hsmw-highlight-main-type
3) 395 11,24 0,03 0,50% 11,24 0,03 0,50% -hsmw-highlight-check-path
4) 22 6,02 0,27 0,27% 6,02 0,27 0,27% -hsmw-highlight-string
5) 6 2,26 0,38 0,10% 2,26 0,38 0,10% -hsmw-highlight-dollar-string
6) 1 0,07 0,07 0,00% 0,07 0,07 0,00% -hsmw-highlight-fill-option-variables
7) 1 0,01 0,01 0,00% 0,01 0,01 0,00% -hsmw-highlight-init
Messages sorted by:
Reverse Date,
Date,
Thread,
Author