olabusayoT commented on code in PR #1435:
URL: https://github.com/apache/daffodil/pull/1435#discussion_r1956828927


##########
daffodil-runtime1/src/main/scala/org/apache/daffodil/runtime1/processors/dfa/CreateDelimiterDFA.scala:
##########
@@ -186,26 +186,33 @@ object CreateDelimiterDFA {
   private def buildTransitions(
     nextState: DelimStateBase,
     delim: Seq[DelimBase],
-    allStates: ArrayBuffer[State],
+    allStates: Array[State],
     ignoreCase: Boolean
   ): State = {
 
-    if (delim.isEmpty && nextState != null) {
-      // We are initial state
-      nextState.stateName = "StartState" // "PTERM0"
-      return nextState
+    var i = 0
+    var remainingDelim = delim
+    var currentNextState = nextState
+
+    while (remainingDelim.nonEmpty) {
+      val currentState = getState(
+        remainingDelim.head,
+        if (currentNextState == null) DFA.FinalState else 
currentNextState.stateNum,
+        remainingDelim.length - 1,
+        allStates,
+        ignoreCase
+      )
+      remainingDelim = remainingDelim.tail
+      allStates(i) = currentState
+      currentNextState = currentState
+      i += 1
     }
 
-    val currentState = getState(
-      delim(0),
-      if (nextState == null) DFA.FinalState else nextState.stateNum,
-      delim.length - 1,
-      allStates,
-      ignoreCase
-    )
-    val rest = delim.tail
+    if (currentNextState != null) {
+      // We are initial state
+      currentNextState.stateName = "StartState" // "PTERM0"
+    }
 
-    allStates += currentState
-    return buildTransitions(currentState, rest, allStates, ignoreCase)

Review Comment:
   because allStates is an Array instead of ArrayBuffer, we needed to be able 
to assign the value to it using an index, and a while loop seemed more straight 
forward than doing recursion...hence the refactor



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to