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