Skip to content

Commit 74254b9

Browse files
authored
perf: avoid project output clone (#11707)
1 parent 446c795 commit 74254b9

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

crates/common/src/contracts.rs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,22 @@ impl<'a> ContractsByArtifactBuilder<'a> {
119119
Self { artifacts: artifacts.into_iter().collect(), storage_layouts: BTreeMap::new() }
120120
}
121121

122-
/// Adds storage layouts from `ProjectCompileOutput` to known artifacts.
123-
pub fn with_storage_layouts(mut self, output: ProjectCompileOutput) -> Self {
124-
self.storage_layouts = output
125-
.into_artifacts()
126-
.filter_map(|(id, artifact)| artifact.storage_layout.map(|layout| (id, layout)))
127-
.collect();
122+
/// Add storage layouts from the given `ProjectCompileOutput` to known artifacts.
123+
pub fn with_output(self, output: &ProjectCompileOutput, base: &Path) -> Self {
124+
self.with_storage_layouts(output.artifact_ids().filter_map(|(id, artifact)| {
125+
artifact
126+
.storage_layout
127+
.as_ref()
128+
.map(|layout| (id.with_stripped_file_prefixes(base), layout.clone()))
129+
}))
130+
}
131+
132+
/// Add storage layouts.
133+
pub fn with_storage_layouts(
134+
mut self,
135+
layouts: impl IntoIterator<Item = (ArtifactId, StorageLayout)>,
136+
) -> Self {
137+
self.storage_layouts.extend(layouts);
128138
self
129139
}
130140

crates/forge/src/multi_runner.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -535,9 +535,8 @@ impl MultiContractRunnerBuilder {
535535
}
536536

537537
// Create known contracts from linked contracts and storage layout information (if any).
538-
let known_contracts = ContractsByArtifactBuilder::new(linked_contracts)
539-
.with_storage_layouts(output.clone().with_stripped_file_prefixes(root))
540-
.build();
538+
let known_contracts =
539+
ContractsByArtifactBuilder::new(linked_contracts).with_output(output, root).build();
541540

542541
Ok(MultiContractRunner {
543542
contracts: deployable_contracts,

0 commit comments

Comments
 (0)