f686d7
From 941f312444dfda4d0d1d02edcfbae9dc1ec6b95e Mon Sep 17 00:00:00 2001
f686d7
From: Peter Stephenson <pws@zsh.org>
f686d7
Date: Mon, 8 Sep 2014 16:38:51 +0100
f686d7
Subject: [PATCH] users/19059 based on users/19058: remove ineffiency with
f686d7
 multiple * matches
f686d7
f686d7
Upstream-commit: 8bf3595e3a05f0cea7f12c463a0df09e4010cd1c
f686d7
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
f686d7
---
f686d7
 Src/pattern.c     | 10 ++++++++++
f686d7
 Test/D02glob.ztst |  9 ++++++++-
f686d7
 2 files changed, 18 insertions(+), 1 deletion(-)
f686d7
f686d7
diff --git a/Src/pattern.c b/Src/pattern.c
f686d7
index 53ada0f..b74a08a 100644
f686d7
--- a/Src/pattern.c
f686d7
+++ b/Src/pattern.c
f686d7
@@ -2911,6 +2911,16 @@ patmatch(Upat prog)
f686d7
 	    break;
f686d7
 	case P_STAR:
f686d7
 	    /* Handle specially for speed, although really P_ONEHASH+P_ANY */
f686d7
+	    while (P_OP(next) == P_STAR) {
f686d7
+		/*
f686d7
+		 * If there's another * following we can optimise it
f686d7
+		 * out.  Chains of *'s can give pathologically bad
f686d7
+		 * performance.
f686d7
+		 */
f686d7
+		scan = next;
f686d7
+		next = PATNEXT(scan);
f686d7
+	    }
f686d7
+	    /*FALLTHROUGH*/
f686d7
 	case P_ONEHASH:
f686d7
 	case P_TWOHASH:
f686d7
 	    /*
f686d7
diff --git a/Test/D02glob.ztst b/Test/D02glob.ztst
f686d7
index 0aea261..5709e5c 100644
f686d7
--- a/Test/D02glob.ztst
f686d7
+++ b/Test/D02glob.ztst
f686d7
@@ -433,3 +433,10 @@
f686d7
  print glob.tmp/dir5/N<->(N)
f686d7
 0:Numeric glob is not usurped by process substitution.
f686d7
 >glob.tmp/dir5/N123
f686d7
+
f686d7
+# The following should not cause excessive slowdown.
f686d7
+  print glob.tmp/*.*
f686d7
+  print glob.tmp/**************************.*************************
f686d7
+0:Optimisation to squeeze multiple *'s used as ordinary glob wildcards.
f686d7
+>glob.tmp/ra=1.0_et=3.5
f686d7
+>glob.tmp/ra=1.0_et=3.5
f686d7
-- 
f686d7
2.1.0
f686d7