From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21656 invoked from network); 3 May 1999 01:07:38 -0000 Received: from sunsite.auc.dk (130.225.51.30) by ns1.primenet.com.au with SMTP; 3 May 1999 01:07:38 -0000 Received: (qmail 23364 invoked by alias); 3 May 1999 01:07:32 -0000 Mailing-List: contact zsh-workers-help@sunsite.auc.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 6188 Received: (qmail 23356 invoked from network); 3 May 1999 01:07:30 -0000 From: "Bart Schaefer" Message-Id: <990502180725.ZM11286@candle.brasslantern.com> Date: Sun, 2 May 1999 18:07:25 -0700 X-Mailer: Z-Mail (4.0b.820 20aug96) To: zsh-workers@sunsite.auc.dk Subject: PATCH: 3.1.5-pws-17: Faster "compinit" MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii 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