Outsource: ids iterator to files vector

This commit is contained in:
Matthias Beyer 2015-12-04 23:35:48 +01:00
parent 55f740497b
commit f8e870312e

View file

@ -81,9 +81,7 @@ impl StorageBackend {
.and_then(|ids| { .and_then(|ids| {
debug!("Iterating ids and building files from them"); debug!("Iterating ids and building files from them");
debug!(" number of ids = {}", ids.len()); debug!(" number of ids = {}", ids.len());
Ok(ids.filter_map(|id| self.get_file_by_id(m, &id, p)) Ok(self.filter_map_ids_to_files(m, p, ids).into_iter())
.collect::<Vec<File>>()
.into_iter())
}) })
.map_err(|e| { .map_err(|e| {
debug!("StorageBackend::iter_ids() returned error = {:?}", e); debug!("StorageBackend::iter_ids() returned error = {:?}", e);
@ -198,9 +196,8 @@ impl StorageBackend {
let globstr = self.prefix_of_files_for_module(m) + "*" + &id_str[..] + ".imag"; let globstr = self.prefix_of_files_for_module(m) + "*" + &id_str[..] + ".imag";
debug!("Globbing with globstr = '{}'", globstr); debug!("Globbing with globstr = '{}'", globstr);
glob(&globstr[..]).map(|globlist| { glob(&globstr[..]).map(|globlist| {
let mut vec = globlist_to_file_id_vec(globlist).into_iter() let idvec = globlist_to_file_id_vec(globlist).into_iter();
.filter_map(|id| self.get_file_by_id(m, &id, p)) let mut vec = self.filter_map_ids_to_files(m, p, idvec);
.collect::<Vec<File>>();
vec.reverse(); vec.reverse();
vec.pop() vec.pop()
}).unwrap_or({ }).unwrap_or({
@ -270,6 +267,17 @@ impl StorageBackend {
self.storepath.clone() + m.name() self.storepath.clone() + m.name()
} }
fn filter_map_ids_to_files<'a, HP>(&self,
m: &'a Module,
p: &Parser<HP>,
ids: IntoIter<FileID>)
-> Vec<File<'a>>
where HP: FileHeaderParser
{
ids.filter_map(|id| self.get_file_by_id(m, &id, p))
.collect::<Vec<File>>()
}
} }
#[derive(Debug)] #[derive(Debug)]
@ -335,3 +343,4 @@ fn globlist_to_file_id_vec(globlist: Paths) -> Vec<FileID> {
.map(|pbuf| FileID::from(&pbuf)) .map(|pbuf| FileID::from(&pbuf))
.collect::<Vec<FileID>>() .collect::<Vec<FileID>>()
} }