sortByPriority static method
Stable sort by SintMiddleware.priority: among equal priorities the original declaration order is preserved (Dart's List.sort is NOT stable). Shared by MiddlewareRunner and SintDelegate.runMiddleware so both middleware pipelines agree on ordering (1.5.0).
Implementation
static List<SintMiddleware> sortByPriority(
List<SintMiddleware> middlewares) {
final indexed = <MapEntry<int, SintMiddleware>>[
for (var i = 0; i < middlewares.length; i++)
MapEntry(i, middlewares[i]),
];
indexed.sort((a, b) {
final cmp = a.value.priority.compareTo(b.value.priority);
return cmp != 0 ? cmp : a.key.compareTo(b.key);
});
return [for (final entry in indexed) entry.value];
}