[Pcre-svn] [1165] code/trunk: When computing minimum length,…

Top Page
Delete this message
Author: Subversion repository
Date:  
To: pcre-svn
Subject: [Pcre-svn] [1165] code/trunk: When computing minimum length, don' t scan subsequent branches if any branch in
Revision: 1165
          http://www.exim.org/viewvc/pcre2?view=rev&revision=1165
Author:   ph10
Date:     2019-09-07 16:16:10 +0100 (Sat, 07 Sep 2019)
Log Message:
-----------
When computing minimum length, don't scan subsequent branches if any branch in 
a group has zero minimum length.


Modified Paths:
--------------
    code/trunk/ChangeLog
    code/trunk/src/pcre2_study.c


Modified: code/trunk/ChangeLog
===================================================================
--- code/trunk/ChangeLog    2019-09-06 16:08:45 UTC (rev 1164)
+++ code/trunk/ChangeLog    2019-09-07 15:16:10 UTC (rev 1165)
@@ -139,7 +139,11 @@
 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
---------------------------


Modified: code/trunk/src/pcre2_study.c
===================================================================
--- code/trunk/src/pcre2_study.c    2019-09-06 16:08:45 UTC (rev 1164)
+++ code/trunk/src/pcre2_study.c    2019-09-07 15:16:10 UTC (rev 1165)
@@ -223,7 +223,9 @@


     /* 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 @@
     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;