@@ -21,6 +21,7 @@ pub struct Import {
2121 shared : Shared ,
2222 chain : ChainController ,
2323 switch : Switch ,
24+ num_threads : usize ,
2425}
2526
2627impl Import {
@@ -30,12 +31,14 @@ impl Import {
3031 shared : Shared ,
3132 source : ImportSource ,
3233 switch : Switch ,
34+ num_threads : usize ,
3335 ) -> Self {
3436 Import {
3537 chain,
3638 shared,
3739 source,
3840 switch,
41+ num_threads,
3942 }
4043 }
4144
@@ -78,7 +81,7 @@ impl Import {
7881 }
7982
8083 let f: Box < dyn Read + Send > = match & self . source {
81- ImportSource :: Path ( source) => Box :: new ( fs:: File :: open ( & source) ?) ,
84+ ImportSource :: Path ( source) => Box :: new ( fs:: File :: open ( source) ?) ,
8285 ImportSource :: Stdin => {
8386 // read from stdin
8487 Box :: new ( std:: io:: stdin ( ) )
@@ -134,7 +137,7 @@ impl Import {
134137 #[ cfg( feature = "progress_bar" ) ]
135138 let progress_bar = {
136139 let bar = match & self . source {
137- ImportSource :: Path ( source) => ProgressBar :: new ( fs:: metadata ( & source) ?. len ( ) ) ,
140+ ImportSource :: Path ( source) => ProgressBar :: new ( fs:: metadata ( source) ?. len ( ) ) ,
138141 ImportSource :: Stdin => ProgressBar :: new_spinner ( ) ,
139142 } ;
140143 let style = ProgressStyle :: default_bar ( )
@@ -148,10 +151,12 @@ impl Import {
148151 const BLOCKS_COUNT_PER_CHUNK : usize = 1024 * 6 ;
149152 let ( blocks_tx, blocks_rx) = ckb_channel:: bounded :: < Arc < BlockView > > ( BLOCKS_COUNT_PER_CHUNK ) ;
150153 std:: thread:: spawn ( {
154+ let num_threads = self . num_threads ;
151155 #[ cfg( feature = "progress_bar" ) ]
152156 let progress_bar = progress_bar. clone ( ) ;
153157 move || {
154158 let pool = rayon:: ThreadPoolBuilder :: new ( )
159+ . num_threads ( num_threads)
155160 . build ( )
156161 . expect ( "rayon thread pool must build" ) ;
157162 pool. install ( || {
0 commit comments