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