zsh-workers
 help / color / mirror / code / Atom feed
From: Sven Wischnowsky <wischnow@informatik.hu-berlin.de>
To: zsh-workers@sunsite.auc.dk
Subject: PATCH: some small speedups
Date: Mon, 13 Dec 1999 13:01:42 +0100 (MET)	[thread overview]
Message-ID: <199912131201.NAA27154@beta.informatik.hu-berlin.de> (raw)


This should make some things a tiny bit faster...

- avoiding some parameter expansions in a loop in _path_files
- avoid calling _files more than once in some functions
- avoid calling ps(1) twice in _pids -- one comment for this one:
  maybe we should replace the arguments and list-arguments styles with 
  two new styles that give the whole command, not only the arguments
  to ps?

And this patch also replaces the calls to compstyle in compinit with
calls to zstyle. I simply forgot to change them before.


Btw, at the weekend I remembered that I had once written myself a
small shell function profiling module -- anyone interested?

Bye
 Sven

diff -u -r ../oz/Completion/Builtins/_pids Completion/Builtins/_pids
--- ../oz/Completion/Builtins/_pids	Fri Dec 10 15:23:25 1999
+++ Completion/Builtins/_pids	Sun Dec 12 00:23:20 1999
@@ -3,7 +3,7 @@
 # If given the `-m <pattern>' option, this tries to complete only pids
 # of processes whose command line match the `<pattern>'.
 
-local list expl match desc listargs args
+local out list expl match desc listargs args
 
 _wanted processes expl 'process ID' || return 1
 
@@ -12,12 +12,18 @@
   shift 2
 fi
 
-zstyle -a ":completion${curcontext}:ps" list-arguments listargs
 zstyle -a ":completion${curcontext}:ps" arguments args
-(( $#listargs )) || listargs=( "$args[@]" )
+
+out="$(command ps $args 2>/dev/null)"
 
 if zstyle -t ":completion${curcontext}:processes" verbose; then
-  list=("${(@Mr:COLUMNS-1:)${(f@)$(command ps $listargs 2>/dev/null)}[2,-1]:#[ 	]#${PREFIX}[0-9]#${SUFFIX}[ 	]*${~match}}")
+  zstyle -a ":completion${curcontext}:ps" list-arguments listargs
+  (( $#listargs )) || listargs=( "$args[@]" )
+  if [[ "$listargs" = "$args" ]]; then
+    list=("${(@Mr:COLUMNS-1:)${(f@)out}[2,-1]:#[ 	]#${PREFIX}[0-9]#${SUFFIX}[ 	]*${~match}}")
+  else
+    list=("${(@Mr:COLUMNS-1:)${(f@)$(command ps $listargs 2>/dev/null)}[2,-1]:#[ 	]#${PREFIX}[0-9]#${SUFFIX}[ 	]*${~match}}")
+  fi
   desc=(-ld list)
 else
   desc=()
diff -u -r ../oz/Completion/Core/_path_files Completion/Core/_path_files
--- ../oz/Completion/Core/_path_files	Fri Dec 10 15:23:30 1999
+++ Completion/Core/_path_files	Sun Dec 12 00:28:00 1999
@@ -6,7 +6,7 @@
 local linepath realpath donepath prepath testpath exppath
 local tmp1 tmp2 tmp3 tmp4 i orig pre suf tpre tsuf opre osuf cpre
 local pats haspats=no ignore group expl addpfx addsfx remsfx
-local nm=$compstate[nmatches] menu match matcher mopts
+local nm=$compstate[nmatches] menu match matcher mopts atmp
 
 typeset -U prepaths exppaths
 
@@ -366,12 +366,12 @@
 	fi
       else
         if [[ "$tmp3" = */* ]]; then
+	  atmp=( -Qf "$mopts[@]" -p "$linepath$tmp4"
+	         -W "$prepath$realpath$testpath" "$ignore[@]"
+	         "$addpfx[@]" "$addsfx[@]" "$remsfx[@]"
+                 -M "r:|/=* r:|=* $match" "$group[@]" "$expl[@]" )
           for i in "$tmp1[@]"; do
-	    compadd -Qf "$mopts[@]" -p "$linepath$tmp4" -s "/${i#*/}" \
-		    -W "$prepath$realpath$testpath" "$ignore[@]" \
-		    "$addpfx[@]" "$addsfx[@]" "$remsfx[@]" \
-                    -M "r:|/=* r:|=* $match" "$group[@]" "$expl[@]" \
-		    - "${i%%/*}"
+	    compadd "$args[@]" -s "/${i#*/}" - "${i%%/*}"
 	  done
         else
 	  compadd -Qf "$mopts[@]" -p "$linepath$tmp4" \
diff -u -r ../oz/Completion/User/_cvs Completion/User/_cvs
--- ../oz/Completion/User/_cvs	Fri Dec 10 15:23:33 1999
+++ Completion/User/_cvs	Sat Dec 11 00:47:46 1999
@@ -578,7 +578,7 @@
     omit=(${pref}*(D:t))
     eval 'entries=(${entries:#('${(j:|:)${(@)omit:q}}')})'
     _tags directories && compadd "$@" -P "$qpref" - ${entries:q} ||
-    _cvs_directories "$@"
+        _cvs_directories "$@"
   else
     _files "$@"
   fi
@@ -595,9 +595,9 @@
     omit=($_cvs_ignore_default ${entries:q} ${=cvsignore})
     [[ -r ~/.cvsignore ]] && omit=($omit $(<~/.cvsignore))
     [[ -r ${pref}.cvsignore ]] && omit=($omit $(<${pref}.cvsignore))
-    _files "$@" -g '*~(*/|)('${(j:|:)omit}')(D)' ||
-    _files "$@" -g '*~(*/|)('${(j:|:)${(@)entries:q}}')(D)' ||
-    _cvs_directories "$@"
+    _path_files "$@" -g '*~(*/|)('${(j:|:)omit}')(D)' ||
+        _path_files "$@" -g '*~(*/|)('${(j:|:)${(@)entries:q}}')(D)' ||
+        _cvs_directories "$@"
   else
     _files "$@"
   fi
diff -u -r ../oz/Completion/User/_pbm Completion/User/_pbm
--- ../oz/Completion/User/_pbm	Fri Dec 10 15:23:35 1999
+++ Completion/User/_pbm	Sat Dec 11 01:00:09 1999
@@ -21,7 +21,7 @@
     _description files expl 'picture file'
     set -- "$expl[@]"
   fi
-  _files "$@" -g "$pat" || _files "$@" -g '*.(#i)p[bgp]m'
+  _path_files "$@" -g "$pat" || _files "$@" -g '*.(#i)p[bgp]m'
   return
 fi
 
@@ -774,5 +774,5 @@
 
 *)
   _description files expl 'picture file'
-  _files "$expl[@]" -g "$pat" || _files "$expl[@]" -g '*.(#i)p[bgp]m'
+  _path_files "$expl[@]" -g "$pat" || _files "$expl[@]" -g '*.(#i)p[bgp]m'
 esac

--
Sven Wischnowsky                         wischnow@informatik.hu-berlin.de


             reply	other threads:[~1999-12-13 12:01 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-12-13 12:01 Sven Wischnowsky [this message]
1999-12-13 12:21 ` Adam Spiers
1999-12-13 12:27 Sven Wischnowsky
1999-12-13 12:38 Sven Wischnowsky
1999-12-13 21:31 ` Peter Stephenson
1999-12-14 10:52 Sven Wischnowsky

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=199912131201.NAA27154@beta.informatik.hu-berlin.de \
    --to=wischnow@informatik.hu-berlin.de \
    --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).