in lib/src/algorithms.dart [313:339]
void _mergeSort<E, K>(
List<E> elements,
K Function(E element) keyOf,
int Function(K, K) compare,
int start,
int end,
List<E> target,
int targetOffset) {
var length = end - start;
if (length < _mergeSortLimit) {
_movingInsertionSort<E, K>(
elements, keyOf, compare, start, end, target, targetOffset);
return;
}
var middle = start + (length >> 1);
var firstLength = middle - start;
var secondLength = end - middle;
// Here secondLength >= firstLength (differs by at most one).
var targetMiddle = targetOffset + firstLength;
// Sort the second half into the end of the target area.
_mergeSort(elements, keyOf, compare, middle, end, target, targetMiddle);
// Sort the first half into the end of the source area.
_mergeSort(elements, keyOf, compare, start, middle, elements, middle);
// Merge the two parts into the target area.
_merge(keyOf, compare, elements, middle, middle + firstLength, target,
targetMiddle, targetMiddle + secondLength, target, targetOffset);
}