mbeckerle commented on code in PR #1435: URL: https://github.com/apache/daffodil/pull/1435#discussion_r1956507677
########## 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: So this was tail recursive, but you rewrote it as iterative. Why? I'm ok with the rewrite. We try to avoid functional style overheads in the runtime1 part of daffodil. This little mini compiler of delimiters is very old code before we settled on while-loops as the main thing for runtime1. I just didn't expect to see such a revision in a PR that is about 2.13/3.x conversion. -- 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: commits-unsubscr...@daffodil.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org