summaryrefslogtreecommitdiff
path: root/lib/dfa.c
diff options
context:
space:
mode:
authorNorihiro Tanaka <noritnk@kcn.ne.jp>2020-11-01 16:31:38 +0900
committerJim Meyering <meyering@fb.com>2020-11-01 09:11:51 -0800
commitb5b7b9d2a8a3a69aad7f7249a634ebaf30f4ed2d (patch)
tree3410e2bc2b5852c5f99e4ac0a64cde6b39ef686d /lib/dfa.c
parent701a78c16a420c79699fbed313554f8de280f786 (diff)
downloadgnulib-b5b7b9d2a8a3a69aad7f7249a634ebaf30f4ed2d.tar.gz
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.
Diffstat (limited to 'lib/dfa.c')
-rw-r--r--lib/dfa.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/lib/dfa.c b/lib/dfa.c
index 74aafa2ee9..6d880c1331 100644
--- 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;