stevedlawrence commented on a change in pull request #262: Unordered sequences
URL: https://github.com/apache/incubator-daffodil/pull/262#discussion_r330505225
##########
File path:
daffodil-runtime1/src/main/scala/org/apache/daffodil/infoset/InfosetImpl.scala
##########
@@ -1438,20 +1438,24 @@ sealed class DIComplex(override val erd:
ElementRuntimeData, val tunable: Daffod
}
}
- final def sortChildNodesByPosition(): Unit = {
+ final def sortChildNodesByPosition(start: Int): Unit = {
// TODO: Once we upgrade to Scala 2.13 we can call the inplace sort
method: DAFFODIL-2152
// childNodes.sortInPlace(_.erd.position)
- childNodes = childNodes.sortBy(_.erd.position)
+ val (a, b) = childNodes.splitAt(start)
+ childNodes.clear()
+ childNodes ++= (a ++ b.sortBy(_.erd.position))
Review comment:
Thougts on moving this logic into ``flattendAndValidateChildNodes``? That
way we avoid doubling the splitAt, clear, and append work? Essentially turns
this function into an unordered sequence post process thing that handles
everything about unordered sequences. Could be something like:
```scala
val (ordered, unordered) = childNodes.splitAt(start)
childNodes.clear()
childNodes ++= ordered
val groups = unordered.groupBy(_.erd)
val flattenedNodes = groups.map { case (erd, nodes) =>
// existing array/scala logic here, resulting in a single node
node
}
val sorted = newNodes.sortBy(_.erd.position)
childNodes ++= sorted
}
```
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services