From 11a0c30782f456dc883dcbde69b025026898d90f Mon Sep 17 00:00:00 2001
From: jian he <jian.universality@gmail.com>
Date: Fri, 29 May 2026 23:34:50 +0800
Subject: [PATCH v47 3/3] nfa refactor argument

The functions nfa_advance_alt, nfa_advance_begin, nfa_advance_end, and
nfa_advance_var currently all take the same two parameters:
(RPRNFAState *state, RPRPatternElement *elem)

However (RPRPatternElement *elem) can already be derived from (RPRNFAState *state).
Passing it explicitly is redundant and make it feel confusing.
So I propose to emove the (RPRPatternElement *elem) parameter from these functions.
---
 src/backend/executor/execRPR.c | 36 +++++++++++++++-------------------
 1 file changed, 16 insertions(+), 20 deletions(-)

diff --git a/src/backend/executor/execRPR.c b/src/backend/executor/execRPR.c
index a76bb97cb7d..a81e425337d 100644
--- a/src/backend/executor/execRPR.c
+++ b/src/backend/executor/execRPR.c
@@ -78,17 +78,13 @@ static void nfa_route_to_elem(WindowAggState *winstate, RPRNFAContext *ctx,
 							  RPRNFAState *state, RPRPatternElement *nextElem,
 							  int64 currentPos);
 static void nfa_advance_alt(WindowAggState *winstate, RPRNFAContext *ctx,
-							RPRNFAState *state, RPRPatternElement *elem,
-							int64 currentPos);
+							RPRNFAState *state, int64 currentPos);
 static void nfa_advance_begin(WindowAggState *winstate, RPRNFAContext *ctx,
-							  RPRNFAState *state, RPRPatternElement *elem,
-							  int64 currentPos);
+							  RPRNFAState *state, int64 currentPos);
 static void nfa_advance_end(WindowAggState *winstate, RPRNFAContext *ctx,
-							RPRNFAState *state, RPRPatternElement *elem,
-							int64 currentPos);
+							RPRNFAState *state, int64 currentPos);
 static void nfa_advance_var(WindowAggState *winstate, RPRNFAContext *ctx,
-							RPRNFAState *state, RPRPatternElement *elem,
-							int64 currentPos);
+							RPRNFAState *state, int64 currentPos);
 static void nfa_advance(WindowAggState *winstate, RPRNFAContext *ctx,
 						int64 currentPos);
 
@@ -925,11 +921,11 @@ nfa_route_to_elem(WindowAggState *winstate, RPRNFAContext *ctx,
  */
 static void
 nfa_advance_alt(WindowAggState *winstate, RPRNFAContext *ctx,
-				RPRNFAState *state, RPRPatternElement *elem,
-				int64 currentPos)
+				RPRNFAState *state, int64 currentPos)
 {
 	RPRPattern *pattern = winstate->rpPattern;
 	RPRPatternElement *elements = pattern->elements;
+	RPRPatternElement *elem = &elements[state->elemIdx];
 	RPRElemIdx	altIdx = elem->next;
 
 	while (altIdx >= 0 && altIdx < pattern->numElements)
@@ -963,11 +959,11 @@ nfa_advance_alt(WindowAggState *winstate, RPRNFAContext *ctx,
  */
 static void
 nfa_advance_begin(WindowAggState *winstate, RPRNFAContext *ctx,
-				  RPRNFAState *state, RPRPatternElement *elem,
-				  int64 currentPos)
+				  RPRNFAState *state, int64 currentPos)
 {
 	RPRPattern *pattern = winstate->rpPattern;
 	RPRPatternElement *elements = pattern->elements;
+	RPRPatternElement *elem = &elements[state->elemIdx];
 	RPRNFAState *skipState = NULL;
 
 	state->counts[elem->depth] = 0;
@@ -1024,11 +1020,11 @@ nfa_advance_begin(WindowAggState *winstate, RPRNFAContext *ctx,
  */
 static void
 nfa_advance_end(WindowAggState *winstate, RPRNFAContext *ctx,
-				RPRNFAState *state, RPRPatternElement *elem,
-				int64 currentPos)
+				RPRNFAState *state, int64 currentPos)
 {
 	RPRPattern *pattern = winstate->rpPattern;
 	RPRPatternElement *elements = pattern->elements;
+	RPRPatternElement *elem = &elements[state->elemIdx];
 	int			depth = elem->depth;
 	int32		count = state->counts[depth];
 
@@ -1179,11 +1175,11 @@ nfa_advance_end(WindowAggState *winstate, RPRNFAContext *ctx,
  */
 static void
 nfa_advance_var(WindowAggState *winstate, RPRNFAContext *ctx,
-				RPRNFAState *state, RPRPatternElement *elem,
-				int64 currentPos)
+				RPRNFAState *state, int64 currentPos)
 {
 	RPRPattern *pattern = winstate->rpPattern;
 	RPRPatternElement *elements = pattern->elements;
+	RPRPatternElement *elem = &elements[state->elemIdx];
 	int			depth = elem->depth;
 	int32		count = state->counts[depth];
 	bool		canLoop = (elem->max == RPR_QUANTITY_INF || count < elem->max);
@@ -1354,20 +1350,20 @@ nfa_advance_state(WindowAggState *winstate, RPRNFAContext *ctx,
 			break;
 
 		case RPR_VARID_ALT:
-			nfa_advance_alt(winstate, ctx, state, elem, currentPos);
+			nfa_advance_alt(winstate, ctx, state, currentPos);
 			break;
 
 		case RPR_VARID_BEGIN:
-			nfa_advance_begin(winstate, ctx, state, elem, currentPos);
+			nfa_advance_begin(winstate, ctx, state, currentPos);
 			break;
 
 		case RPR_VARID_END:
-			nfa_advance_end(winstate, ctx, state, elem, currentPos);
+			nfa_advance_end(winstate, ctx, state, currentPos);
 			break;
 
 		default:
 			/* VAR element */
-			nfa_advance_var(winstate, ctx, state, elem, currentPos);
+			nfa_advance_var(winstate, ctx, state, currentPos);
 			break;
 	}
 }
-- 
2.34.1

