Skip to content

Commit 9cdae29

Browse files
committed
Small performance enhancements.
1 parent 50c7eb6 commit 9cdae29

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

lib/src/conflict-helper.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,9 @@ export const reconstructConflict = async (
4242
const oursVal = getByPath(ours, path);
4343
const theirsVal = getByPath(theirs, path);
4444

45-
const oursStr = await serialize(format, oursVal);
46-
const theirsStr = await serialize(format, theirsVal);
45+
const [oursStr, theirsStr] = await Promise.all(
46+
[oursVal, theirsVal].map(val => serialize(format, val)),
47+
);
4748

4849
const block = [
4950
"<<<<<<< ours",
@@ -53,10 +54,8 @@ export const reconstructConflict = async (
5354
">>>>>>> theirs",
5455
].join("\n");
5556

56-
serialized = serialized.replace(
57-
JSON.stringify(`__CONFLICT_MARKER::${path}__`), // works for JSON
58-
block,
59-
);
57+
const marker = `__CONFLICT_MARKER::${path}__`;
58+
serialized = serialized.replace(/json/.test(format) ? JSON.stringify(marker) : marker, block);
6059
}
6160

6261
return serialized;

lib/src/file-serializer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export const serialize = async (format: string, value: unknown): Promise<string>
99
}
1010
case "toml": {
1111
const { stringify } = await import("smol-toml");
12-
return stringify(value as any);
12+
return stringify(value);
1313
}
1414
case "xml": {
1515
const { XMLBuilder } = await import("fast-xml-parser");

0 commit comments

Comments
 (0)