about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Stephenson <pws@zsh.org>2014-09-08 16:38:51 +0100
committerPeter Stephenson <pws@zsh.org>2014-09-08 16:38:51 +0100
commit8bf3595e3a05f0cea7f12c463a0df09e4010cd1c (patch)
tree1dd75aa5b3921cee250da7c2db2d2b91dbf939ca
parent956829c18e8ade666083f1c69043a16a80f70b0d (diff)
downloadzsh-8bf3595e3a05f0cea7f12c463a0df09e4010cd1c.tar.gz
zsh-8bf3595e3a05f0cea7f12c463a0df09e4010cd1c.tar.xz
zsh-8bf3595e3a05f0cea7f12c463a0df09e4010cd1c.zip
users/19059 based on users/19058: remove ineffiency with multiple * matches
-rw-r--r--ChangeLog6
-rw-r--r--Src/pattern.c10
-rw-r--r--Test/D02glob.ztst7
3 files changed, 23 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 18fde9344..fde649892 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2014-09-08  Peter Stephenson  <p.stephenson@samsung.com>
+
+	* users/19059 based on users/19058 (Paulo César Pereira de
+	Andrade): Src/pattern.c, Test/D02glob.ztst: remove inefficiency
+	with multiple "*"s in pattern matching and add test.
+
 2014-09-07  Barton E. Schaefer  <schaefer@zsh.org>
 
 	* 33122: Src/Modules/pcre.c, Test/V07pcre.ztst: typo from 32891
diff --git a/Src/pattern.c b/Src/pattern.c
index 94a299ebb..df5e602ca 100644
--- a/Src/pattern.c
+++ b/Src/pattern.c
@@ -3012,6 +3012,16 @@ patmatch(Upat prog)
 	    break;
 	case P_STAR:
 	    /* Handle specially for speed, although really P_ONEHASH+P_ANY */
+	    while (P_OP(next) == P_STAR) {
+		/*
+		 * If there's another * following we can optimise it
+		 * out.  Chains of *'s can give pathologically bad
+		 * performance.
+		 */
+		scan = next;
+		next = PATNEXT(scan);
+	    }
+	    /*FALLTHROUGH*/
 	case P_ONEHASH:
 	case P_TWOHASH:
 	    /*
diff --git a/Test/D02glob.ztst b/Test/D02glob.ztst
index 4697ca414..217ce7c06 100644
--- a/Test/D02glob.ztst
+++ b/Test/D02glob.ztst
@@ -565,3 +565,10 @@
   print $match[1]
 0:(#q) is ignored completely in conditional pattern matching
 >fichier
+
+# The following should not cause excessive slowdown.
+  print glob.tmp/*.*
+  print glob.tmp/**************************.*************************
+0:Optimisation to squeeze multiple *'s used as ordinary glob wildcards.
+>glob.tmp/ra=1.0_et=3.5
+>glob.tmp/ra=1.0_et=3.5