Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

PATCH: some small speedups



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@xxxxxxxxxxxxxxxxxxxxxxx



Messages sorted by: Reverse Date, Date, Thread, Author