Minor optimization for bin and binstalk (#646)

* Refactor `logging`: Extract `report_err`
* Optimize `get_default_pkg_url_template`: Return iter instead of `Vec`
   to avoid heap allocation.
* Refactor `GhCrateMeta::find`: Rm `launch_baseline_find_tasks`
* Optimize `GhCrateMeta::find`: Avoid cloning `Cow<'_, str>`
* Improve `report_err` output: Print newline after msg

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
Jiahao XU 2023-01-24 23:58:07 +11:00 committed by GitHub
parent 283163bbda
commit eb95c5b799
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 41 additions and 26 deletions

View file

@ -44,7 +44,9 @@ impl RepositoryHost {
}
}
pub fn get_default_pkg_url_template(self) -> Option<Vec<String>> {
pub fn get_default_pkg_url_template(
self,
) -> Option<impl Iterator<Item = String> + Clone + 'static> {
use RepositoryHost::*;
match self {
@ -82,11 +84,14 @@ impl RepositoryHost {
}
}
fn apply_filenames_to_paths(paths: &[&str], filenames: &[&[&str]], suffix: &str) -> Vec<String> {
fn apply_filenames_to_paths(
paths: &'static [&'static str],
filenames: &'static [&'static [&'static str]],
suffix: &'static str,
) -> impl Iterator<Item = String> + Clone + 'static {
filenames
.iter()
.flat_map(|fs| fs.iter())
.cartesian_product(paths.iter())
.map(|(filename, path)| format!("{path}/{filename}{suffix}"))
.collect()
.map(move |(filename, path)| format!("{path}/{filename}{suffix}"))
}