Merge pull request #598 from FliegendeWurst/s-none-sorting

Optimize file table creation, fixes #484 as a side-effect
This commit is contained in:
Benjamin Sago 2020-01-19 09:32:17 +00:00 committed by GitHub
commit 352afd40c3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -61,6 +61,7 @@
use std::io::{Write, Error as IOError, Result as IOResult}; use std::io::{Write, Error as IOError, Result as IOResult};
use std::mem::MaybeUninit;
use std::path::PathBuf; use std::path::PathBuf;
use std::vec::IntoIter as VecIntoIter; use std::vec::IntoIter as VecIntoIter;
@ -194,13 +195,13 @@ impl<'a> Render<'a> {
use log::error; use log::error;
use crate::fs::feature::xattr; use crate::fs::feature::xattr;
let mut file_eggs = Vec::new(); let mut file_eggs = (0..src.len()).map(|_| MaybeUninit::uninit()).collect::<Vec<_>>();
pool.scoped(|scoped| { pool.scoped(|scoped| {
let file_eggs = Arc::new(Mutex::new(&mut file_eggs)); let file_eggs = Arc::new(Mutex::new(&mut file_eggs));
let table = table.as_ref(); let table = table.as_ref();
for file in src { for (idx, file) in src.iter().enumerate() {
let file_eggs = Arc::clone(&file_eggs); let file_eggs = Arc::clone(&file_eggs);
scoped.execute(move || { scoped.execute(move || {
@ -267,11 +268,13 @@ impl<'a> Render<'a> {
} else { None }; } else { None };
let egg = Egg { table_row, xattrs, errors, dir, file, icon }; let egg = Egg { table_row, xattrs, errors, dir, file, icon };
file_eggs.lock().unwrap().push(egg); unsafe { std::ptr::write(file_eggs.lock().unwrap()[idx].as_mut_ptr(), egg) }
}); });
} }
}); });
// this is safe because all entries have been initialized above
let mut file_eggs = unsafe { std::mem::transmute::<_, Vec<Egg>>(file_eggs) };
self.filter.sort_files(&mut file_eggs); self.filter.sort_files(&mut file_eggs);
for (tree_params, egg) in depth.iterate_over(file_eggs.into_iter()) { for (tree_params, egg) in depth.iterate_over(file_eggs.into_iter()) {