Skip to content

Commit

Permalink
Simplify normalizeFilesystemOperations further
Browse files Browse the repository at this point in the history
  • Loading branch information
adamziel committed Nov 5, 2023
1 parent 4cf5315 commit 9d36b30
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions packages/php-wasm/fs-journal/src/lib/fs-journal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,19 +296,19 @@ export function normalizeFilesystemOperations(
originalJournal: FilesystemOperation[]
): FilesystemOperation[] {
let changed;
let rev: FilesystemOperation[] = [...originalJournal].reverse();
let entries: FilesystemOperation[] = [...originalJournal];
do {
changed = false;
for (let i = 0; i < rev.length; i++) {
for (let i = entries.length - 1; i >= 0; i--) {
const replacements: any = {};
for (let j = i + 1; j < rev.length; j++) {
const formerType = checkRelationship(rev[i], rev[j]);
for (let j = i - 1; j >= 0; j--) {
const formerType = checkRelationship(entries[i], entries[j]);
if (formerType === 'none') {
continue;
}

const latter = rev[i];
const former = rev[j];
const latter = entries[i];
const former = entries[j];
if (
latter.operation === 'RENAME' &&
former.operation === 'RENAME'
Expand Down Expand Up @@ -354,11 +354,11 @@ export function normalizeFilesystemOperations(
// the new location.
replacements[j] = [];
replacements[i] = [
...(replacements[i] || []),
{
...former,
path: latter.toPath,
},
...(replacements[i] || []),
];
continue;
}
Expand All @@ -368,7 +368,6 @@ export function normalizeFilesystemOperations(
// to creating it in the new location.
replacements[j] = [];
replacements[i] = [
...(replacements[i] || []),
{
...former,
path: joinPaths(
Expand All @@ -378,6 +377,7 @@ export function normalizeFilesystemOperations(
)
),
},
...(replacements[i] || []),
];
continue;
}
Expand All @@ -402,7 +402,7 @@ export function normalizeFilesystemOperations(
}
if (Object.entries(replacements).length > 0) {
changed = true;
rev = rev.flatMap((op, index) => {
entries = entries.flatMap((op, index) => {
if (!(index in replacements)) {
return [op];
}
Expand All @@ -412,7 +412,7 @@ export function normalizeFilesystemOperations(
}
}
} while (changed);
return rev.reverse();
return entries;
}

type RelatedOperationInfo = 'same_node' | 'ancestor' | 'descendant' | 'none';
Expand Down

0 comments on commit 9d36b30

Please sign in to comment.