perf(comparison): reuse canonical sort keys (#990)

This commit is contained in:
morluto authored and GitHub committed 2026-10-07 23:54:09 +08:00
1 parent 2cedde9f1c
commit ebb065e2dc
2 files changed
+119 -9

No files matched your search

+13 -9
View File
@@ -177,15 +177,19 @@ export const stringAndNameProjection = (
};
export const sorted = (values: readonly unknown[]): readonly unknown[] =>
[...values].sort((left, right) => {
const leftJson = canonicalJson(left, "Function normalization");
const rightJson = canonicalJson(right, "Function normalization");
// Preserve existing collation while ordering distinct values within a tie.
return (
leftJson.localeCompare(rightJson) ||
compareCodePoints(leftJson, rightJson)
);
});
values
.map((value) => ({
value,
json: canonicalJson(value, "Function normalization"),
}))
.sort((left, right) => {
// Preserve existing collation while ordering distinct values within a tie.
return (
left.json.localeCompare(right.json) ||
compareCodePoints(left.json, right.json)
);
})
.map(({ value }) => value);
export const combineCoverage = <Item>(
left: FunctionCollection<Item>,