From c65794ac7066e2101831dd3c52d14a5864c29955 Mon Sep 17 00:00:00 2001
From: jian he <jian.universality@gmail.com>
Date: Fri, 29 May 2026 14:29:53 +0800
Subject: [PATCH v47 2/3] remove nfa related function name

rename nfa_context_alloc() to nfa_context_make().
rename nfa_state_create() to nfa_state_clone().
---
 src/backend/executor/README.rpr       |  2 +-
 src/backend/executor/execRPR.c        | 58 +++++++++++++--------------
 src/test/regress/expected/rpr_nfa.out |  2 +-
 src/test/regress/sql/rpr_nfa.sql      |  2 +-
 4 files changed, 32 insertions(+), 32 deletions(-)

diff --git a/src/backend/executor/README.rpr b/src/backend/executor/README.rpr
index 05e1609a666..b116047e16a 100644
--- a/src/backend/executor/README.rpr
+++ b/src/backend/executor/README.rpr
@@ -556,7 +556,7 @@ VI-2. Context Creation: ExecRPRStartContext()
 
 Creates a new context and performs the initial advance.
 
-  (1) Allocate context via nfa_context_alloc()
+  (1) Allocate context via nfa_context_make()
   (2) Set matchStartRow = pos
   (3) Create initial state: elemIdx=0 (first pattern element),
       counts=all zero
diff --git a/src/backend/executor/execRPR.c b/src/backend/executor/execRPR.c
index 8664cf7acc3..a76bb97cb7d 100644
--- a/src/backend/executor/execRPR.c
+++ b/src/backend/executor/execRPR.c
@@ -39,11 +39,11 @@
 #define BITNUM(x)	((x) % BITS_PER_BITMAPWORD)
 
 /* Forward declarations - NFA state management */
-static RPRNFAState *nfa_state_alloc(WindowAggState *winstate);
+static RPRNFAState *nfa_state_make(WindowAggState *winstate);
 static void nfa_state_free(WindowAggState *winstate, RPRNFAState *state);
 static void nfa_state_free_list(WindowAggState *winstate, RPRNFAState *list);
-static RPRNFAState *nfa_state_create(WindowAggState *winstate, int16 elemIdx,
-									 int32 *counts, bool sourceAbsorbable);
+static RPRNFAState *nfa_state_clone(WindowAggState *winstate, int16 elemIdx,
+									int32 *counts, bool sourceAbsorbable);
 static bool nfa_states_equal(WindowAggState *winstate, RPRNFAState *s1,
 							 RPRNFAState *s2);
 static bool nfa_add_state_unique(WindowAggState *winstate, RPRNFAContext *ctx,
@@ -52,7 +52,7 @@ static void nfa_add_matched_state(WindowAggState *winstate, RPRNFAContext *ctx,
 								  RPRNFAState *state, int64 matchEndRow);
 
 /* Forward declarations - NFA context management (internal) */
-static RPRNFAContext *nfa_context_alloc(WindowAggState *winstate);
+static RPRNFAContext *nfa_context_make(WindowAggState *winstate);
 static void nfa_unlink_context(WindowAggState *winstate, RPRNFAContext *ctx);
 
 /* Forward declarations - NFA statistics */
@@ -184,14 +184,14 @@ static void nfa_advance(WindowAggState *winstate, RPRNFAContext *ctx,
  */
 
 /*
- * nfa_state_alloc
+ * nfa_state_make
  *
- * Allocate an NFA state, reusing from freeList if available.
+ * Make a new RPRNFAState state, reusing from freeList if available.
  * freeList is stored in WindowAggState for reuse across match attempts.
  * Uses flexible array member for counts[].
  */
 static RPRNFAState *
-nfa_state_alloc(WindowAggState *winstate)
+nfa_state_make(WindowAggState *winstate)
 {
 	int			nfaStateSize;
 	RPRNFAState *state;
@@ -252,7 +252,7 @@ nfa_state_free_list(WindowAggState *winstate, RPRNFAState *list)
 }
 
 /*
- * nfa_state_create
+ * nfa_state_clone
  *
  * Create a new state with given elemIdx and counts.
  * isAbsorbable is computed immediately: inherited AND new element's flag.
@@ -261,12 +261,12 @@ nfa_state_free_list(WindowAggState *winstate, RPRNFAState *list)
  * Caller is responsible for linking the returned state.
  */
 static RPRNFAState *
-nfa_state_create(WindowAggState *winstate, int16 elemIdx,
-				 int32 *counts, bool sourceAbsorbable)
+nfa_state_clone(WindowAggState *winstate, int16 elemIdx,
+				int32 *counts, bool sourceAbsorbable)
 {
 	RPRPattern *pattern = winstate->rpPattern;
 	int			maxDepth = pattern->maxDepth;
-	RPRNFAState *state = nfa_state_alloc(winstate);
+	RPRNFAState *state = nfa_state_make(winstate);
 	RPRPatternElement *elem = &pattern->elements[elemIdx];
 
 	state->elemIdx = elemIdx;
@@ -392,12 +392,12 @@ nfa_add_matched_state(WindowAggState *winstate, RPRNFAContext *ctx,
 }
 
 /*
- * nfa_context_alloc
+ * nfa_context_make
  *
  * Allocate an NFA context, reusing from free list if available.
  */
 static RPRNFAContext *
-nfa_context_alloc(WindowAggState *winstate)
+nfa_context_make(WindowAggState *winstate)
 {
 	RPRNFAContext *ctx;
 
@@ -904,8 +904,8 @@ nfa_route_to_elem(WindowAggState *winstate, RPRNFAContext *ctx,
 
 		/* Create skip state before add_unique, which may free state */
 		if (RPRElemCanSkip(nextElem))
-			skipState = nfa_state_create(winstate, nextElem->next,
-										 state->counts, state->isAbsorbable);
+			skipState = nfa_state_clone(winstate, nextElem->next,
+										state->counts, state->isAbsorbable);
 
 		nfa_add_state_unique(winstate, ctx, state);
 
@@ -942,8 +942,8 @@ nfa_advance_alt(WindowAggState *winstate, RPRNFAContext *ctx,
 			break;
 
 		/* Create independent state for each branch */
-		newState = nfa_state_create(winstate, altIdx,
-									state->counts, state->isAbsorbable);
+		newState = nfa_state_clone(winstate, altIdx,
+								   state->counts, state->isAbsorbable);
 
 		/* Recursively process this branch before next */
 		nfa_advance_state(winstate, ctx, newState, currentPos);
@@ -975,8 +975,8 @@ nfa_advance_begin(WindowAggState *winstate, RPRNFAContext *ctx,
 	/* Optional group: create skip path (but don't route yet) */
 	if (elem->min == 0)
 	{
-		skipState = nfa_state_create(winstate, elem->jump,
-									 state->counts, state->isAbsorbable);
+		skipState = nfa_state_clone(winstate, elem->jump,
+									state->counts, state->isAbsorbable);
 	}
 
 	if (skipState != NULL && RPRElemIsReluctant(elem))
@@ -1053,8 +1053,8 @@ nfa_advance_end(WindowAggState *winstate, RPRNFAContext *ctx,
 		 *----------
 		 */
 		if (RPRElemCanEmptyLoop(elem))
-			ffState = nfa_state_create(winstate, state->elemIdx,
-									   state->counts, state->isAbsorbable);
+			ffState = nfa_state_clone(winstate, state->elemIdx,
+									  state->counts, state->isAbsorbable);
 
 		/* Primary path: loop back for real matches */
 		for (int d = depth + 1; d < pattern->maxDepth; d++)
@@ -1122,8 +1122,8 @@ nfa_advance_end(WindowAggState *winstate, RPRNFAContext *ctx,
 		 * Create exit state first (need original counts before modifying
 		 * state)
 		 */
-		exitState = nfa_state_create(winstate, elem->next,
-									 state->counts, state->isAbsorbable);
+		exitState = nfa_state_clone(winstate, elem->next,
+									state->counts, state->isAbsorbable);
 		exitState->counts[depth] = 0;
 		nextElem = &elements[exitState->elemIdx];
 
@@ -1211,8 +1211,8 @@ nfa_advance_var(WindowAggState *winstate, RPRNFAContext *ctx,
 			RPRNFAState *savedMatch = ctx->matchedState;
 
 			/* Clone for exit, original stays for loop */
-			cloneState = nfa_state_create(winstate, elem->next,
-										  state->counts, state->isAbsorbable);
+			cloneState = nfa_state_clone(winstate, elem->next,
+										 state->counts, state->isAbsorbable);
 			cloneState->counts[depth] = 0;
 			nextElem = &elements[cloneState->elemIdx];
 
@@ -1243,8 +1243,8 @@ nfa_advance_var(WindowAggState *winstate, RPRNFAContext *ctx,
 		else
 		{
 			/* Clone for loop, original used for exit */
-			cloneState = nfa_state_create(winstate, state->elemIdx,
-										  state->counts, state->isAbsorbable);
+			cloneState = nfa_state_clone(winstate, state->elemIdx,
+										 state->counts, state->isAbsorbable);
 
 			/* Loop first (preferred for greedy) */
 			nfa_add_state_unique(winstate, ctx, cloneState);
@@ -1439,9 +1439,9 @@ ExecRPRStartContext(WindowAggState *winstate, int64 startPos)
 	RPRPattern *pattern = winstate->rpPattern;
 	RPRPatternElement *elem;
 
-	ctx = nfa_context_alloc(winstate);
+	ctx = nfa_context_make(winstate);
 	ctx->matchStartRow = startPos;
-	ctx->states = nfa_state_alloc(winstate);	/* initial state at elem 0 */
+	ctx->states = nfa_state_make(winstate); /* initial state at elem 0 */
 
 	elem = &pattern->elements[0];
 
diff --git a/src/test/regress/expected/rpr_nfa.out b/src/test/regress/expected/rpr_nfa.out
index a19b26c3b94..2e819d97734 100644
--- a/src/test/regress/expected/rpr_nfa.out
+++ b/src/test/regress/expected/rpr_nfa.out
@@ -3806,7 +3806,7 @@ WINDOW w AS (
 
 -- Non-absorbable context during absorption
 -- Pattern (A B)+ C: A,B in absorbable group, C is not.
--- When END exits to C via nfa_state_create, isAbsorbable becomes false.
+-- When END exits to C via nfa_state_clone, isAbsorbable becomes false.
 WITH test_non_absorbable AS (
     SELECT * FROM (VALUES
         (1, ARRAY['A']),
diff --git a/src/test/regress/sql/rpr_nfa.sql b/src/test/regress/sql/rpr_nfa.sql
index 1d27e0dc09e..5ddfaa1fcde 100644
--- a/src/test/regress/sql/rpr_nfa.sql
+++ b/src/test/regress/sql/rpr_nfa.sql
@@ -2761,7 +2761,7 @@ WINDOW w AS (
 
 -- Non-absorbable context during absorption
 -- Pattern (A B)+ C: A,B in absorbable group, C is not.
--- When END exits to C via nfa_state_create, isAbsorbable becomes false.
+-- When END exits to C via nfa_state_clone, isAbsorbable becomes false.
 WITH test_non_absorbable AS (
     SELECT * FROM (VALUES
         (1, ARRAY['A']),
-- 
2.34.1

