From 27d40c8ad8ec7488ed7be34b3ecc3926388dd827 Mon Sep 17 00:00:00 2001 From: "Philip.Hazel" Date: Sat, 7 Sep 2019 15:16:10 +0000 Subject: [PATCH] When computing minimum length, don't scan subsequent branches if any branch in a group has zero minimum length. --- ChangeLog | 4 ++++ src/pcre2_study.c | 6 ++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9f3796c..219ff80 100644 --- a/ChangeLog +++ b/ChangeLog @@ -139,6 +139,10 @@ case after a bumpalong and (b) when one case has been found, it searches only up to that position for an earlier occurrence of the other case. This fix applies to both interpretive pcre2_match() and to pcre2_dfa_match(). +30. While scanning to find the minimum length of a group, if any branch has +minimum length zero, there is no need to scan any subsequent branches (a small +compile-time performance improvement). + Version 10.33 16-April-2019 --------------------------- diff --git a/src/pcre2_study.c b/src/pcre2_study.c index 280ad57..6370e17 100644 --- a/src/pcre2_study.c +++ b/src/pcre2_study.c @@ -223,7 +223,9 @@ for (;;) /* Reached end of a branch; if it's a ket it is the end of a nested call. If it's ALT it is an alternation in a nested call. If it is END it's - the end of the outer call. All can be handled by the same code. */ + the end of the outer call. All can be handled by the same code. If the + length of any branch is zero, there is no need to scan any subsequent + branches. */ case OP_ALT: case OP_KET: @@ -233,7 +235,7 @@ for (;;) case OP_END: if (length < 0 || (!had_recurse && branchlength < length)) length = branchlength; - if (op != OP_ALT) return length; + if (op != OP_ALT || length == 0) return length; nextbranch = cc + GET(cc, 1); cc += 1 + LINK_SIZE; branchlength = 0;