Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
[PATCH] Clean but not very effective optimization (lex.c / dupstring_wlen)
- X-seq: zsh-workers 43695
- From: Sebastian Gniazdowski <sgniazdowski@xxxxxxxxx>
- To: Zsh hackers list <zsh-workers@xxxxxxx>
- Subject: [PATCH] Clean but not very effective optimization (lex.c / dupstring_wlen)
- Date: Wed, 17 Oct 2018 00:08:01 +0200
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=kLuf5+gkCcR20OjtwoAEQpeqVeZuQGBwESh4RzUkZaI=; b=kJw2w50yNXUCzvMYxJwSWBbqWfyy24VjO79GPGgyR4WRMY3TLUwC/gtX5x+gaa5ycU Mz0Fr1kiMkn0/C9x2PDddlGxn10s2OylEZGdxYk8PKqWwCgJHhRFX9HHBPuXDIC5cng5 +UYHwN9kcS66PPUWDlbuG4LAvPyhN5wXZB7XBAdCc3VkHR64WDoRSVGEZ23zFbcFhue0 jVtO+z94C1LYXz9yPVl8IqTNBRyLcVcRDzzGBlWs17qi1qWgCbygEi0bKXJee34+sv3R Yh8XTKm2XEMbqvXSV1kIuZVXVCn37lwhsnn7ZheQfjR9j6erMeuKnHsgH4Z5orb7oD2x FucA==
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- List-unsubscribe: <mailto:zsh-workers-unsubscribe@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
Hello,
dupstring_wlen (i.e. with-len) is ready to use, so this patch is just
4 changes dupstring(s) -> dupstring_wlen(s, l). Each of those
dupstrings has a nice strlen() invocation already there in lex.c, a
few lines above.
Callgrind doesn't report any real change in number of instructions of
strlen() call and a test that repeatedly invokes (z) flag on a 32-line
buffer 150 times reports 24 ms for both unoptimized and optimized
version.
However performance test of F-Sy-Highlighting reports rather stable 40
ms gain – out of ~3000 ms, so not much.
In general simplicity of this patch made me send it.
--
Sebastian Gniazdowski
News: https://twitter.com/ZdharmaI
IRC: https://kiwiirc.com/client/chat.freenode.net:+6697/#zplugin
Blog: http://zdharma.org
diff --git a/Src/lex.c b/Src/lex.c
index 44ad880..fa29da3 100644
--- a/Src/lex.c
+++ b/Src/lex.c
@@ -1626,7 +1626,7 @@ parsestrnoerr(char **s)
zcontext_save();
untokenize(*s);
- inpush(dupstring(*s), 0, NULL);
+ inpush(dupstring_wlen(*s, l), 0, NULL);
strinbeg(0);
lexbuf.len = 0;
lexbuf.ptr = tokstr = *s;
@@ -1658,7 +1658,7 @@ parse_subscript(char *s, int sub, int endchar)
if (!*s || *s == endchar)
return 0;
zcontext_save();
- untokenize(t = dupstring(s));
+ untokenize(t = dupstring_wlen(s, l));
inpush(t, 0, NULL);
strinbeg(0);
/*
@@ -1674,7 +1674,7 @@ parse_subscript(char *s, int sub, int endchar)
* length preservation.
*/
lexbuf.len = 0;
- lexbuf.ptr = tokstr = dupstring(s);
+ lexbuf.ptr = tokstr = dupstring_wlen(s, l);
lexbuf.siz = l + 1;
err = dquote_parse(endchar, sub);
toklen = (int)(lexbuf.ptr - tokstr);
@@ -1713,7 +1713,7 @@ parse_subst_string(char *s)
return 0;
zcontext_save();
untokenize(s);
- inpush(dupstring(s), 0, NULL);
+ inpush(dupstring_wlen(s, l), 0, NULL);
strinbeg(0);
lexbuf.len = 0;
lexbuf.ptr = tokstr = s;
Messages sorted by:
Reverse Date,
Date,
Thread,
Author