mirror of
https://github.com/morluto/rea
synced 2026-10-27 14:42:18 -04:00
perf(javascript): cache canonical export comparison sort keys (#1028)
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
import { uniqueSorted } from "../canonicalOrdering.js";
|
||||
import { digestExportShapeValue } from "./javascriptExportShapeComparisonIdentity.js";
|
||||
import { compareCodePoints, uniqueSorted } from "../canonicalOrdering.js";
|
||||
import {
|
||||
canonicalExportShapeValue,
|
||||
digestExportShapeValue,
|
||||
} from "./javascriptExportShapeComparisonIdentity.js";
|
||||
import {
|
||||
javaScriptExportShapeComparisonResultSchema,
|
||||
type JavaScriptExportShapeComparisonChange,
|
||||
@@ -14,7 +17,6 @@ import {
|
||||
} from "./javascriptExportShapeSelection.js";
|
||||
import {
|
||||
buildJavaScriptExportShapeChanges,
|
||||
compareJavaScriptExportShapeChanges,
|
||||
hasPartialJavaScriptExportPropertyCoverage,
|
||||
pairJavaScriptExportShapeVariants,
|
||||
type JavaScriptExportShapePairing,
|
||||
@@ -42,14 +44,16 @@ export const compareJavaScriptExportShapes = (
|
||||
input.left.evidenceId,
|
||||
input.right.evidenceId,
|
||||
);
|
||||
const allChanges = buildJavaScriptExportShapeChanges({
|
||||
leftSelection: left,
|
||||
rightSelection: right,
|
||||
pairing,
|
||||
leftShapes: leftRetained.shapes,
|
||||
rightShapes: rightRetained.shapes,
|
||||
evidenceLinks,
|
||||
}).sort(compareJavaScriptExportShapeChanges);
|
||||
const allChanges = sortChanges(
|
||||
buildJavaScriptExportShapeChanges({
|
||||
leftSelection: left,
|
||||
rightSelection: right,
|
||||
pairing,
|
||||
leftShapes: leftRetained.shapes,
|
||||
rightShapes: rightRetained.shapes,
|
||||
evidenceLinks,
|
||||
}),
|
||||
);
|
||||
const changes = allChanges;
|
||||
const omittedChanges = 0;
|
||||
const coverage = comparisonCoverage({
|
||||
@@ -78,6 +82,29 @@ export const compareJavaScriptExportShapes = (
|
||||
});
|
||||
};
|
||||
|
||||
const sortChanges = (
|
||||
changes: readonly JavaScriptExportShapeComparisonChange[],
|
||||
): JavaScriptExportShapeComparisonChange[] =>
|
||||
changes
|
||||
.map((change, index) => ({
|
||||
change,
|
||||
index,
|
||||
sortKey: canonicalExportShapeValue({
|
||||
discriminant: change.discriminant,
|
||||
path: change.path,
|
||||
status: change.status,
|
||||
left_source_range: change.left_source_range,
|
||||
right_source_range: change.right_source_range,
|
||||
change_id: change.change_id,
|
||||
}),
|
||||
}))
|
||||
.sort(
|
||||
(left, right) =>
|
||||
compareCodePoints(left.sortKey, right.sortKey) ||
|
||||
left.index - right.index,
|
||||
)
|
||||
.map(({ change }) => change);
|
||||
|
||||
interface CoverageInput {
|
||||
readonly input: JavaScriptExportShapeComparisonProjectionInput;
|
||||
readonly left: SelectedJavaScriptExport;
|
||||
|
||||
Reference in New Issue
Block a user