]> Savannah Git Hosting - gnulib.git/commitdiff
dfa: retain sequences of similar nodes in optimization
authorNorihiro Tanaka <noritnk@kcn.ne.jp>
Sun, 1 Nov 2020 07:31:38 +0000 (16:31 +0900)
committerJim Meyering <meyering@fb.com>
Sun, 1 Nov 2020 17:11:51 +0000 (09:11 -0800)
DFA was merging similar nodes when it should not.  For example,
it would convert a+a+a to a+a.  Now, a sequence of similar nodes
is not merged.

Problem reported by Gonzalo Padrino in https://bugs.gnu.org/44351

* lib/dfa.c (merge_nfa_state): Skip the follow for repetition in
optimization.

ChangeLog
lib/dfa.c

index b9097469424a3942eaa96047b29c45306e416be2..25c386e6c344351855106ce245480b3f4c00bf38 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2020-11-01  Norihiro Tanaka  <noritnk@kcn.ne.jp>
+
+       dfa: retain sequences of similar nodes in optimization
+       DFA was merging similar nodes when it should not.  For example,
+       it would convert a+a+a to a+a.  Now, a sequence of similar nodes
+       is not merged.  Problem reported by Gonzalo Padrino in
+       https://bugs.gnu.org/44351
+       * lib/dfa.c (merge_nfa_state): Skip the follow for repetition in
+       optimization.
+
 2020-11-01  Jim Meyering  <meyering@fb.com>
 
        test-dfa-match-aux.c: accept EREs, not BREs
index 74aafa2ee9b0c5643f9cbb68182adc367b2a32ee..6d880c13314395fc7da37aec3c86c0fc594e35c9 100644 (file)
--- a/lib/dfa.c
+++ b/lib/dfa.c
@@ -2438,7 +2438,7 @@ merge_nfa_state (struct dfa *d, idx_t tindex, char *flags,
           continue;
         }
 
-      if (!(flags[sindex] & (OPT_LPAREN | OPT_RPAREN)))
+      if (sindex != tindex && !(flags[sindex] & (OPT_LPAREN | OPT_RPAREN)))
         {
           idx_t j;
 
@@ -2446,6 +2446,9 @@ merge_nfa_state (struct dfa *d, idx_t tindex, char *flags,
             {
               idx_t dindex = follows[tindex].elems[j].index;
 
+              if (dindex == tindex)
+                continue;
+
               if (follows[tindex].elems[j].constraint != iconstraint)
                 continue;