Skip to content

Commit ef7bb3f

Browse files
committed
[perf] rephrase some egregious ld.cloneDeep calls
1 parent e653508 commit ef7bb3f

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

src/command/render/render-contexts.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -756,20 +756,17 @@ export async function projectMetadataForInputFile(
756756
input: string,
757757
project: ProjectContext,
758758
): Promise<Metadata> {
759-
// don't mutate caller
760-
project = ld.cloneDeep(project) as ProjectContext;
761-
762759
if (project.dir && project.config) {
763760
// If there is directory and configuration information
764761
// process paths
765762
return toInputRelativePaths(
766763
projectType(project.config?.project?.[kProjectType]),
767764
project.dir,
768765
dirname(input),
769-
project.config,
766+
ld.cloneDeep(project.config),
770767
) as Metadata;
771768
} else {
772769
// Just return the config or empty metadata
773-
return project.config || {};
770+
return ld.cloneDeep(project.config) || {};
774771
}
775772
}

src/project/project-context.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -653,11 +653,15 @@ async function resolveProjectExtension(
653653
return projectConfig;
654654
}
655655

656+
// migrate 'site' to 'website'
657+
// TODO make this a deprecation warning
656658
function migrateProjectConfig(projectConfig: ProjectConfig) {
657-
projectConfig = ld.cloneDeep(projectConfig);
658-
659-
// migrate 'site' to 'website'
660659
const kSite = "site";
660+
if (projectConfig[kSite] === undefined) {
661+
return projectConfig;
662+
}
663+
664+
projectConfig = ld.cloneDeep(projectConfig);
661665
if (projectConfig.project[kProjectType] === kSite) {
662666
projectConfig.project[kProjectType] = kWebsite;
663667
}

0 commit comments

Comments
 (0)