diff --git a/src/commands/debug_files/find.rs b/src/commands/debug_files/find.rs index 879ec48e8e..4b63cf2517 100644 --- a/src/commands/debug_files/find.rs +++ b/src/commands/debug_files/find.rs @@ -224,7 +224,7 @@ fn find_ids_for_dsym( if dirent.path().extension() != Some(OsStr::new("class")); if let Ok(dif) = DifFile::open_path(dirent.path(), Some(DifType::Dsym)); then { - return Some(extract_remaining_ids(&dif.ids(), remaining, DifType::Dsym)) + return Some(extract_remaining_ids(dif.ids(), remaining, DifType::Dsym)) } } None @@ -237,7 +237,7 @@ fn find_ids_for_elf( if_chain! { if let Ok(dif) = DifFile::open_path(dirent.path(), Some(DifType::Elf)); then { - return Some(extract_remaining_ids(&dif.ids(), remaining, DifType::Elf)) + return Some(extract_remaining_ids(dif.ids(), remaining, DifType::Elf)) } } None @@ -252,7 +252,7 @@ fn find_ids_for_pe( dirent.path().extension() == Some(OsStr::new("dll")); if let Ok(dif) = DifFile::open_path(dirent.path(), Some(DifType::Pe)); then { - return Some(extract_remaining_ids(&dif.ids(), remaining, DifType::Pe)) + return Some(extract_remaining_ids(dif.ids(), remaining, DifType::Pe)) } } None @@ -266,7 +266,7 @@ fn find_ids_for_pdb( if dirent.path().extension() == Some(OsStr::new("pdb")); if let Ok(dif) = DifFile::open_path(dirent.path(), Some(DifType::Pdb)); then { - return Some(extract_remaining_ids(&dif.ids(), remaining, DifType::Pdb)) + return Some(extract_remaining_ids(dif.ids(), remaining, DifType::Pdb)) } } None @@ -280,7 +280,7 @@ fn find_ids_for_portablepdb( if dirent.path().extension() == Some(OsStr::new("pdb")); if let Ok(dif) = DifFile::open_path(dirent.path(), Some(DifType::PortablePdb)); then { - return Some(extract_remaining_ids(&dif.ids(), remaining, DifType::PortablePdb)) + return Some(extract_remaining_ids(dif.ids(), remaining, DifType::PortablePdb)) } } None @@ -294,7 +294,7 @@ fn find_ids_for_sourcebundle( if dirent.path().extension() == Some(OsStr::new("zip")); if let Ok(dif) = DifFile::open_path(dirent.path(), Some(DifType::SourceBundle)); then { - return Some(extract_remaining_ids(&dif.ids(), remaining, DifType::SourceBundle)) + return Some(extract_remaining_ids(dif.ids(), remaining, DifType::SourceBundle)) } } None @@ -308,25 +308,27 @@ fn find_ids_for_breakpad( if dirent.path().extension() == Some(OsStr::new("sym")); if let Ok(dif) = DifFile::open_path(dirent.path(), Some(DifType::Breakpad)); then { - return Some(extract_remaining_ids(&dif.ids(), remaining, DifType::Breakpad)) + return Some(extract_remaining_ids(dif.ids(), remaining, DifType::Breakpad)) } } None } -fn extract_remaining_ids( - ids: &[DebugId], +fn extract_remaining_ids( + ids: I, remaining: &HashSet, t: DifType, -) -> Vec<(DebugId, DifType)> { - ids.iter() - .filter_map(|id| { - if remaining.contains(id) { - return Some((id.to_owned(), t)); - } - None - }) - .collect() +) -> Vec<(DebugId, DifType)> +where + I: Iterator, +{ + ids.filter_map(|id| { + if remaining.contains(&id) { + return Some((id.to_owned(), t)); + } + None + }) + .collect() } pub fn execute(matches: &ArgMatches) -> Result<()> { diff --git a/src/utils/dif.rs b/src/utils/dif.rs index bedb20eb30..cf510dad91 100644 --- a/src/utils/dif.rs +++ b/src/utils/dif.rs @@ -1,6 +1,6 @@ -use std::fmt; use std::path::Path; use std::str; +use std::{fmt, iter}; use anyhow::{bail, Context as _, Error, Result}; use proguard::ProguardMapping; @@ -327,16 +327,19 @@ impl<'a> DifFile<'a> { } } - pub fn ids(&self) -> Vec { - match self { - DifFile::Archive(archive) => archive - .get() - .objects() - .filter_map(Result::ok) - .map(|object| object.debug_id()) - .collect(), - DifFile::Proguard(pg) => vec![pg.get().uuid().into()], - } + pub fn ids(&self) -> impl Iterator + '_ { + let rv: Box> = match self { + DifFile::Archive(archive) => Box::new( + archive + .get() + .objects() + .filter_map(Result::ok) + .map(|object| object.debug_id()), + ), + DifFile::Proguard(pg) => Box::new(iter::once(pg.get().uuid().into())), + }; + + rv } pub fn features(&self) -> ObjectDifFeatures { @@ -407,7 +410,7 @@ impl<'a> DifFile<'a> { } fn has_ids(&self) -> bool { - self.ids().iter().any(|id| !id.is_nil()) + self.ids().any(|id| !id.is_nil()) } }