From 8bf3595e3a05f0cea7f12c463a0df09e4010cd1c Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Mon, 8 Sep 2014 16:38:51 +0100 Subject: users/19059 based on users/19058: remove ineffiency with multiple * matches --- ChangeLog | 6 ++++++ Src/pattern.c | 10 ++++++++++ Test/D02glob.ztst | 7 +++++++ 3 files changed, 23 insertions(+) diff --git a/ChangeLog b/ChangeLog index 18fde9344..fde649892 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2014-09-08 Peter Stephenson + + * 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 * 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 -- cgit 1.4.1