@@ -11,6 +11,7 @@ use foundry_compilers::{
11
11
artifacts:: { CompactContractBytecodeCow , Libraries } ,
12
12
contracts:: ArtifactContracts ,
13
13
} ;
14
+ use rayon:: prelude:: * ;
14
15
use semver:: Version ;
15
16
use std:: {
16
17
collections:: { BTreeMap , BTreeSet } ,
@@ -174,7 +175,7 @@ impl<'a> Linker<'a> {
174
175
175
176
// Link and collect bytecodes for `libs_to_deploy`.
176
177
let libs_to_deploy = libs_to_deploy
177
- . into_iter ( )
178
+ . into_par_iter ( )
178
179
. map ( |( id, _) | {
179
180
Ok ( self . link ( id, & libraries) ?. get_bytecode_bytes ( ) . unwrap ( ) . into_owned ( ) )
180
181
} )
@@ -198,7 +199,7 @@ impl<'a> Linker<'a> {
198
199
self . collect_dependencies ( target, & mut needed_libraries) ?;
199
200
200
201
let mut needed_libraries = needed_libraries
201
- . into_iter ( )
202
+ . into_par_iter ( )
202
203
. filter ( |id| {
203
204
// Filter out already provided libraries.
204
205
let ( file, name) = self . convert_artifact_id_to_lib_path ( id) ;
@@ -233,9 +234,9 @@ impl<'a> Linker<'a> {
233
234
234
235
let ( file, name) = self . convert_artifact_id_to_lib_path ( id) ;
235
236
236
- for ( _, bytecode) in & mut needed_libraries {
237
+ needed_libraries . par_iter_mut ( ) . for_each ( | ( _, bytecode) | {
237
238
bytecode. to_mut ( ) . link ( & file. to_string_lossy ( ) , & name, address) ;
238
- }
239
+ } ) ;
239
240
240
241
libraries. libs . entry ( file) . or_default ( ) . insert ( name, address. to_checksum ( None ) ) ;
241
242
}
@@ -295,14 +296,18 @@ impl<'a> Linker<'a> {
295
296
& self ,
296
297
libraries : & Libraries ,
297
298
) -> Result < ArtifactContracts , LinkerError > {
298
- self . contracts . keys ( ) . map ( |id| Ok ( ( id . clone ( ) , self . link ( id , libraries ) ? ) ) ) . collect ( )
299
+ self . get_linked_artifacts_cow ( libraries ) . map ( ArtifactContracts :: from_iter )
299
300
}
300
301
301
302
pub fn get_linked_artifacts_cow (
302
303
& self ,
303
304
libraries : & Libraries ,
304
305
) -> Result < ArtifactContracts < CompactContractBytecodeCow < ' a > > , LinkerError > {
305
- self . contracts . keys ( ) . map ( |id| Ok ( ( id. clone ( ) , self . link ( id, libraries) ?) ) ) . collect ( )
306
+ self . contracts
307
+ . par_iter ( )
308
+ . map ( |( id, _) | Ok ( ( id. clone ( ) , self . link ( id, libraries) ?) ) )
309
+ . collect :: < Result < _ , _ > > ( )
310
+ . map ( ArtifactContracts )
306
311
}
307
312
}
308
313
0 commit comments