From: "Bart Schaefer" <schaefer@brasslantern.com>
To: zsh-workers@sunsite.auc.dk
Subject: PATCH: 3.1.5-pws-17: Faster "compinit"
Date: Sun, 2 May 1999 18:07:25 -0700 [thread overview]
Message-ID: <990502180725.ZM11286@candle.brasslantern.com> (raw)
Not as fast as loading the dumpfile, obviously, but quite a bit faster than
without the patch. There are probably other things that could be done, but
this does an obvious one: There are a couple of "if" cascades inside loops
that can be directly rewritten as "case" statements, thereby expanding the
variable only once. It might even be faster still, in the second case, to
use "if [[ "$_i_line[2]" = (complete-word|delete-char-or-list|etc.etc.) ]]",
but not as readable/maintainable IMO.
Note use of the relatively new fall-through case syntax. One thing this
shows is that case statements still don't know how to xtrace themselves, so
leaving it the slower way might be preferable during debugging.
In one other case, I pulled a test that expands a variable but doesn't rely
on the loop variable out of the loop. Probably not terribly significant as
that loop doesn't run all that many cycles, but what the heck.
Index: Completion/Core/compinit
===================================================================
RCS file: /extra/cvsroot/zsh/zsh-3.1/Completion/Core/compinit,v
retrieving revision 1.5
diff -u -r1.5 compinit
--- compinit 1999/04/20 16:13:52 1.5
+++ compinit 1999/05/03 01:00:23
@@ -180,9 +180,15 @@
*)
# For commands store the function name in the `_comps'
# associative array, command names as keys.
- for i; do
- [[ -z "$new" || "${+_comps[$i]}" -eq 0 ]] && _comps[$i]="$func"
- done
+ if [[ -z "$new" ]]; then
+ for i; do
+ _comps[$i]="$func"
+ done
+ else
+ for i; do
+ [[ "${+_comps[$i]}" -eq 0 ]] && _comps[$i]="$func"
+ done
+ fi
;;
esac
else
@@ -286,31 +292,36 @@
read -rA _i_line < $_i_file
_i_tag=$_i_line[1]
shift _i_line
- if [[ $_i_tag = '#compdef' ]]; then
+ case $_i_tag in
+ (\#compdef)
if [[ $_i_line[1] = -[pk] ]]; then
compdef ${_i_line[1]}a "${_i_file:t}" "${(@)_i_line[2,-1]}"
else
compdef -na "${_i_file:t}" "${_i_line[@]}"
fi
- elif [[ $_i_tag = '#autoload' ]]; then
+ ;;
+ (\#autoload)
autoload ${_i_file:t}
- fi
+ ;;
+ esac
done
done
bindkey |
while read -rA _i_line; do
- if [[ "$_i_line[2]" = complete-word ||
- "$_i_line[2]" = delete-char-or-list ||
- "$_i_line[2]" = expand-or-complete ||
- "$_i_line[2]" = expand-or-complete-prefix ||
- "$_i_line[2]" = list-choices ||
- "$_i_line[2]" = menu-complete ||
- "$_i_line[2]" = menu-expand-or-complete ||
- "$_i_line[2]" = reverse-menu-complete ]]; then
+ case "$_i_line[2]" in
+ (complete-word) ;&
+ (delete-char-or-list) ;&
+ (expand-or-complete) ;&
+ (expand-or-complete-prefix) ;&
+ (list-choices) ;&
+ (menu-complete) ;&
+ (menu-expand-or-complete) ;&
+ (reverse-menu-complete)
zle -C _complete_$_i_line[2] $_i_line[2] _main_complete
bindkey "${_i_line[1][2,-2]}" _complete_$_i_line[2]
- fi
+ ;;
+ esac
done
unset _i_dir _i_line _i_file _i_tag
--
Bart Schaefer Brass Lantern Enterprises
http://www.well.com/user/barts http://www.brasslantern.com
reply other threads:[~1999-05-03 1:07 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=990502180725.ZM11286@candle.brasslantern.com \
--to=schaefer@brasslantern.com \
--cc=zsh-workers@sunsite.auc.dk \
/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).