@@ -147,7 +147,7 @@ impl Args {
147
147
148
148
if !self . flag_quiet {
149
149
eprintln ! (
150
- "Wrote {} chunks to '{}'. Rows/chunk: {} Num records: {}" ,
150
+ "Wrote {} chunk/s to '{}'. Rows/chunk: {} Num records: {}" ,
151
151
nchunks + 1 ,
152
152
Path :: new( & self . arg_outdir) . canonicalize( ) ?. display( ) ,
153
153
chunk_size,
@@ -159,16 +159,15 @@ impl Args {
159
159
}
160
160
161
161
fn parallel_split ( & self , idx : & Indexed < fs:: File , fs:: File > ) -> CliResult < ( ) > {
162
- let args = self . clone ( ) ;
163
162
let chunk_size;
164
163
let idx_count = idx. count ( ) ;
165
164
166
165
#[ allow( clippy:: cast_precision_loss) ]
167
- let nchunks = if let Some ( flag_chunks) = args . flag_chunks {
166
+ let nchunks = if let Some ( flag_chunks) = self . flag_chunks {
168
167
chunk_size = ( idx_count as f64 / flag_chunks as f64 ) . ceil ( ) as usize ;
169
168
flag_chunks
170
169
} else {
171
- chunk_size = args . flag_size ;
170
+ chunk_size = self . flag_size ;
172
171
util:: num_of_chunks ( idx_count as usize , self . flag_size )
173
172
} ;
174
173
if nchunks == 1 {
@@ -177,38 +176,39 @@ impl Args {
177
176
return self . sequential_split ( ) ;
178
177
}
179
178
180
- util:: njobs ( args . flag_jobs ) ;
179
+ util:: njobs ( self . flag_jobs ) ;
181
180
182
181
// safety: we cannot use ? here because we're in a closure
183
182
( 0 ..nchunks) . into_par_iter ( ) . for_each ( |i| {
184
- let conf = args . rconfig ( ) ;
183
+ let conf = self . rconfig ( ) ;
185
184
// safety: safe to unwrap because we know the file is indexed
186
185
let mut idx = conf. indexed ( ) . unwrap ( ) . unwrap ( ) ;
187
186
// safety: the only way this can fail is if the file first row of the chunk
188
187
// is not a valid CSV record, which is impossible because we're reading
189
188
// from a file with a valid index
190
189
let headers = idx. byte_headers ( ) . unwrap ( ) ;
191
190
192
- let mut wtr = args
191
+ let mut wtr = self
193
192
// safety: the only way this can fail is if we cannot create a file
194
- . new_writer ( headers, i * chunk_size, args . flag_pad )
193
+ . new_writer ( headers, i * chunk_size, self . flag_pad )
195
194
. unwrap ( ) ;
196
195
197
196
// safety: we know that there is more than one chunk, so we can safely
198
197
// seek to the start of the chunk
199
198
idx. seek ( ( i * chunk_size) as u64 ) . unwrap ( ) ;
199
+ let mut write_row;
200
200
for row in idx. byte_records ( ) . take ( chunk_size) {
201
- let row = row. unwrap ( ) ;
202
- wtr. write_byte_record ( & row ) . unwrap ( ) ;
201
+ write_row = row. unwrap ( ) ;
202
+ wtr. write_byte_record ( & write_row ) . unwrap ( ) ;
203
203
}
204
204
// safety: safe to unwrap because we know the writer is a file
205
205
// the only way this can fail is if we cannot write to the file
206
206
wtr. flush ( ) . unwrap ( ) ;
207
207
} ) ;
208
208
209
- if !args . flag_quiet {
209
+ if !self . flag_quiet {
210
210
eprintln ! (
211
- "Wrote {} chunks to '{}'. Rows/chunk: {} Num records: {}" ,
211
+ "Wrote {} chunk/s to '{}'. Rows/chunk: {} Num records: {}" ,
212
212
nchunks,
213
213
Path :: new( & self . arg_outdir) . canonicalize( ) ?. display( ) ,
214
214
chunk_size,
0 commit comments