Skip to content

Commit 352afd4

Browse files
authored
Merge pull request ogham#598 from FliegendeWurst/s-none-sorting
Optimize file table creation, fixes ogham#484 as a side-effect
2 parents 416818f + bbd6db3 commit 352afd4

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/output/details.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
6262

6363
use std::io::{Write, Error as IOError, Result as IOResult};
64+
use std::mem::MaybeUninit;
6465
use std::path::PathBuf;
6566
use std::vec::IntoIter as VecIntoIter;
6667

@@ -194,13 +195,13 @@ impl<'a> Render<'a> {
194195
use log::error;
195196
use crate::fs::feature::xattr;
196197

197-
let mut file_eggs = Vec::new();
198+
let mut file_eggs = (0..src.len()).map(|_| MaybeUninit::uninit()).collect::<Vec<_>>();
198199

199200
pool.scoped(|scoped| {
200201
let file_eggs = Arc::new(Mutex::new(&mut file_eggs));
201202
let table = table.as_ref();
202203

203-
for file in src {
204+
for (idx, file) in src.iter().enumerate() {
204205
let file_eggs = Arc::clone(&file_eggs);
205206

206207
scoped.execute(move || {
@@ -267,11 +268,13 @@ impl<'a> Render<'a> {
267268
} else { None };
268269

269270
let egg = Egg { table_row, xattrs, errors, dir, file, icon };
270-
file_eggs.lock().unwrap().push(egg);
271+
unsafe { std::ptr::write(file_eggs.lock().unwrap()[idx].as_mut_ptr(), egg) }
271272
});
272273
}
273274
});
274275

276+
// this is safe because all entries have been initialized above
277+
let mut file_eggs = unsafe { std::mem::transmute::<_, Vec<Egg>>(file_eggs) };
275278
self.filter.sort_files(&mut file_eggs);
276279

277280
for (tree_params, egg) in depth.iterate_over(file_eggs.into_iter()) {

0 commit comments

Comments
 (0)