From d47346abc076410a531876eb5635d8230c69b72f Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Thu, 20 Aug 2020 10:07:22 -0700 Subject: [PATCH] Avoid pushing duplicate start states in query analysis --- lib/src/query.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/src/query.c b/lib/src/query.c index eba5955f..a156beb9 100644 --- a/lib/src/query.c +++ b/lib/src/query.c @@ -599,7 +599,7 @@ static inline int analysis_state__compare( if (self->stack[i].parse_state > other->stack[i].parse_state) return 1; if (self->stack[i].field_id < other->stack[i].field_id) return -1; if (self->stack[i].field_id > other->stack[i].field_id) return 1; - } + } if (self->step_index < other->step_index) return -1; if (self->step_index > other->step_index) return 1; return 0; @@ -814,6 +814,10 @@ static bool ts_query__analyze_patterns(TSQuery *self, unsigned *impossible_index ); if (exists) { AnalysisSubgraph *subgraph = &subgraphs.contents[subgraph_index]; + if ( + subgraph->start_states.size == 0 || + *array_back(&subgraph->start_states) != state + ) array_push(&subgraph->start_states, state); } }