Skip to content

Commit cd70b9d

Browse files
committed
[perf] no cloneDeep
1 parent 7c1f729 commit cd70b9d

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

src/command/render/pandoc.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -391,9 +391,12 @@ export async function runPandoc(
391391
// save args and metadata so we can print them (we may subsequently edit them)
392392
const printArgs = [...args];
393393
let printMetadata = {
394-
...ld.cloneDeep(options.format.metadata),
394+
...options.format.metadata,
395+
crossref: {
396+
...(options.format.metadata.crossref || {}),
397+
},
395398
...options.flags?.metadata,
396-
};
399+
} as Metadata;
397400

398401
// remove some metadata that are used as parameters to our lua filters
399402
const cleanMetadataForPrinting = (metadata: Metadata) => {
@@ -691,7 +694,7 @@ export async function runPandoc(
691694
),
692695
...extras.metadataOverride || {},
693696
};
694-
printMetadata = mergeConfigs(extras.metadata, printMetadata);
697+
printMetadata = mergeConfigs(extras.metadata || {}, printMetadata);
695698
cleanMetadataForPrinting(printMetadata);
696699
}
697700

@@ -820,7 +823,9 @@ export async function runPandoc(
820823
}
821824

822825
// more cleanup
823-
options.format.metadata = cleanupPandocMetadata(options.format.metadata);
826+
options.format.metadata = cleanupPandocMetadata({
827+
...options.format.metadata,
828+
});
824829
printMetadata = cleanupPandocMetadata(printMetadata);
825830

826831
if (extras[kIncludeInHeader]) {
@@ -1370,21 +1375,20 @@ export async function runPandoc(
13701375
}
13711376
}
13721377

1378+
// this mutates metadata[kClassOption]
13731379
function cleanupPandocMetadata(metadata: Metadata) {
1374-
const cleaned = ld.cloneDeep(metadata);
1375-
13761380
// pdf classoption can end up with duplicaed options
1377-
const classoption = cleaned[kClassOption];
1381+
const classoption = metadata[kClassOption];
13781382
if (Array.isArray(classoption)) {
1379-
cleaned[kClassOption] = ld.uniqBy(
1383+
metadata[kClassOption] = ld.uniqBy(
13801384
classoption.reverse(),
13811385
(option: string) => {
13821386
return option.replace(/=.+$/, "");
13831387
},
13841388
).reverse();
13851389
}
13861390

1387-
return cleaned;
1391+
return metadata;
13881392
}
13891393

13901394
async function resolveExtras(

0 commit comments

Comments
 (0)