internal void SortNewNodeSet(Processor proc, ArrayList sortarray) {
Debug.Assert(0 < sortarray.Count);
int numSorts = sortarray.Count;
XPathSortComparer comparer = new XPathSortComparer(numSorts);
for (int i = 0; i < numSorts; i++) {
Sort sort = (Sort) sortarray[i];
Query expr = proc.GetCompiledQuery(sort.select);
comparer.AddSort(expr, new XPathComparerHelper(sort.order, sort.caseOrder, sort.lang, sort.dataType));
}
List<SortKey> results = new List<SortKey>();
Debug.Assert(proc.ActionStack.Peek() == this, "the trick we are doing with proc.Current will work only if this is topmost frame");
while (NewNextNode(proc)) {
XPathNodeIterator savedNodeset = this.nodeSet;
this.nodeSet = this.newNodeSet; // trick proc.Current node
SortKey key = new SortKey(numSorts, /*originalPosition:*/results.Count, this.newNodeSet.Current.Clone());
for (int j = 0; j < numSorts; j ++) {
key[j] = comparer.Expression(j).Evaluate(this.newNodeSet);
}
results.Add(key);
this.nodeSet = savedNodeset; // restore proc.Current node
}
results.Sort(comparer);
this.newNodeSet = new XPathSortArrayIterator(results);
}