about summary refs log tree commit diff
diff options
context:
space:
mode:
authorSven Wischnowsky <wischnow@users.sourceforge.net>2000-07-24 12:52:41 +0000
committerSven Wischnowsky <wischnow@users.sourceforge.net>2000-07-24 12:52:41 +0000
commit0e8c318b8ee07b6efd14293380cf9b82a862bace (patch)
tree238d68732c2f4783571404227df71d6b91f3e8b6
parent36052b318ba9b174c55c5e0c02e8ed7a5c0bd78f (diff)
downloadzsh-0e8c318b8ee07b6efd14293380cf9b82a862bace.tar.gz
zsh-0e8c318b8ee07b6efd14293380cf9b82a862bace.tar.xz
zsh-0e8c318b8ee07b6efd14293380cf9b82a862bace.zip
optimisations for _multi_parts (12354)
-rw-r--r--ChangeLog5
-rw-r--r--Completion/Core/_multi_parts73
2 files changed, 35 insertions, 43 deletions
diff --git a/ChangeLog b/ChangeLog
index 42a20f170..cb63408b6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2000-07-24  Sven Wischnowsky  <wischnow@zsh.org>
+
+	* 12354: Completion/Core/_multi_parts: optimisations for
+ 	_multi_parts
+	
 2000-07-22  Clint Adams  <schizo@debian.org>
 
 	* 12347: Completion/User/_mutt: options -a, -b, and -c are
diff --git a/Completion/Core/_multi_parts b/Completion/Core/_multi_parts
index 9f70534fc..b59550a7f 100644
--- a/Completion/Core/_multi_parts
+++ b/Completion/Core/_multi_parts
@@ -7,9 +7,9 @@
 # The parts of words from the array that are separated by the
 # separator character are then completed independently.
 
-local sep matches pref npref i tmp1 group expl menu pre suf opre osuf cpre
+local sep pref npref i tmp2 group expl menu pre suf opre osuf cpre
 local opts sopts matcher imm
-typeset -U tmp2
+typeset -U tmp1 matches
 
 # Get the options.
 
@@ -25,15 +25,15 @@ else
 fi
 
 # Get the arguments, first the separator, then the array. The array is 
-# stored in `matches'. Further on this array will always contain those 
-# words from the original array that still match everything we have
+# stored in `tmp1'. Further on the array `matches' will always contain
+# those words from the original array that still match everything we have
 # tried to match while we walk through the string from the line.
 
 sep="$1"
 if [[ "${2[1]}" = '(' ]]; then
-  matches=( ${=2[2,-2]} )
+  tmp1=( ${=2[2,-2]} )
 else
-  matches=( "${(@P)2}" )
+  tmp1=( "${(@P)2}" )
 fi
 
 # In `pre' and `suf' we will hold the prefix and the suffix from the
@@ -59,9 +59,9 @@ pref=''
 # If the string from the line matches at least one of the strings,
 # we use only the matching strings.
 
-compadd -O tmp1 -M "r:|${sep}=* r:|=* $matcher" -a matches
+compadd -O matches -M "r:|${sep}=* r:|=* $matcher" -a tmp1
 
-(( $#tmp1 )) && matches=( "$tmp1[@]" )
+(( $#matches )) || matches=( "$tmp1[@]" )
 
 while true; do
 
@@ -96,8 +96,6 @@ while true; do
     [[ $#tmp1 -eq 0 && -n "$_comp_correct" ]] &&
       compadd -O tmp1 - "${(@)matches%%${sep}*}"
 
-    tmp2=( "$tmp1[@]" )
-
     if [[ $#tmp1 -eq 1 ]]; then
 
       # Only one match. If there are still separators from the line
@@ -118,9 +116,7 @@ while true; do
 	  compadd "$group[@]" "$expl[@]" "$opts[@]" \
                   -M "r:|${sep}=* r:|=* $matcher" - "$pref$matches[1]"
         else
-	  tmp2=( "${(@M)matches:#${tmp1[1]}${sep}*}" )
-
-	  if (( $#tmp2 )); then
+	  if (( $matches[(I)${tmp1[1]}${sep}*] )); then
 	    compadd "$group[@]" "$expl[@]" -p "$pref" -r "$sep" -S "$sep" "$opts[@]" \
                     -M "r:|${sep}=* r:|=* $matcher" - "$tmp1[1]"
           else
@@ -148,6 +144,8 @@ while true; do
 	SUFFIX="$suf"
       fi
 
+      matches=( "${(@M)matches:#(${(j:|:)~tmp1})*}" )
+
       if ! zstyle -t ":completion:${curcontext}:" expand suffix ||
          [[ -n "$menu" || -z "$compstate[insert]" ]]; then
 
@@ -161,44 +159,33 @@ while true; do
         else
 	  tmp2=()
         fi
-        for i in "${(@M)matches:#(${(j:|:)~tmp1})*}"; do
-	  case "$i" in
-	  *${sep})
-            compadd "$group[@]" "$expl[@]" -r "$sep" -S "$sep" "$opts[@]" \
-	            -p "$pref" \
-                    -M "r:|${sep}=* r:|=* $matcher" - "${i%%${sep}*}" && ret=0
-            ;;
-	  ${sep}*)
+
+
+        compadd "$group[@]" "$expl[@]" -r "$sep" -S "$sep" "$opts[@]" \
+	        -p "$pref" "$tmp2[@]" -M "r:|${sep}=* r:|=* $matcher" - \
+                "${(@)${(@M)matches:#*${sep}}%%${sep}*}" && ret=0
+        (( $matches[(I)${sep}*] )) &&
             compadd "$group[@]" "$expl[@]" -S '' "$opts[@]" \
 	            -p "$pref" \
                     -M "r:|${sep}=* r:|=* $matcher" - "$sep" && ret=0
-            ;;
-	  *${sep}*)
-            compadd "$group[@]" "$expl[@]" -r "$sep" -S "$sep" "$opts[@]" \
-	            -p "$pref" \
-                    -M "r:|${sep}=* r:|=* $matcher" - "${i%%${sep}*}" && ret=0
-            ;;
-          *)
-            compadd "$group[@]" "$expl[@]" -S '' "$opts[@]" -p "$pref" \
-                    -M "r:|${sep}=* r:|=* $matcher" - "$i" && ret=0
-            ;;
-          esac
-        done
+        compadd "$group[@]" "$expl[@]" -r "$sep" -S "$sep" "$opts[@]" \
+                -p "$pref" "$tmp2[@]" -M "r:|${sep}=* r:|=* $matcher" - \
+                "${(@)${(@M)matches:#*?${sep}?*}%%${sep}*}" && ret=0
+        compadd "$group[@]" "$expl[@]" -S '' "$opts[@]" -p "$pref" "$tmp2[@]" \
+                -M "r:|${sep}=* r:|=* $matcher" - \
+                "${(@)matches:#*${sep}*}" && ret=0
       else
         # With normal completion we add all matches one-by-one with
 	# the unmatched part as a suffix. This will insert the longest
 	# unambiguous string for all matching strings.
 
-        for i in "${(@M)matches:#(${(j:|:)~tmp1})*}"; do
-	  if [[ "$i" = *${sep}* ]]; then
-            compadd "$group[@]" "$expl[@]" "$opts[@]" \
-	            -p "$pref" -s "${i#*${sep}}" \
-                    -M "r:|${sep}=* r:|=* $matcher" - "${i%%${sep}*}" && ret=0
-          else
-            compadd "$group[@]" "$expl[@]" -S '' "$opts[@]" -p "$pref" \
-                    -M "r:|${sep}=* r:|=* $matcher" - "$i" && ret=0
-          fi
-        done
+        compadd "$group[@]" "$expl[@]" "$opts[@]" \
+	        -p "$pref" -s "${i#*${sep}}" \
+                -M "r:|${sep}=* r:|=* $matcher" - \
+                "${(@)${(@M)matches:#*${sep}*}%%${sep}*}" && ret=0
+        compadd "$group[@]" "$expl[@]" -S '' "$opts[@]" -p "$pref" \
+                -M "r:|${sep}=* r:|=* $matcher" - \
+                "${(@)matches:#*${sep}*}" && ret=0
       fi
       return ret
     else