Small fixes

Summary: Some small perf improvements, remove unnecessary cloning, etc.

Reviewed By: jknoxville

Differential Revision: D22307521

fbshipit-source-id: 91cfd16b0b05a24ec9639c2a2e26d504a6b01de4
This commit is contained in:
Pascal Hartig
2020-06-30 06:18:44 -07:00
committed by Facebook GitHub Bot
parent ceb9c942dc
commit ba0a706bc8
2 changed files with 9 additions and 8 deletions

View File

@@ -59,7 +59,7 @@ fn pack(
let packtype_paths = pack_list let packtype_paths = pack_list
.0 .0
.get(platform) .get(platform)
.ok_or_else(|| error::Error::MissingPlatformDefinition(platform.clone()))?; .ok_or_else(|| error::Error::MissingPlatformDefinition(*platform))?;
let res = packtype_paths let res = packtype_paths
.into_par_iter() .into_par_iter()
.map(|(pack_type, pack_files)| { .map(|(pack_type, pack_files)| {
@@ -89,7 +89,7 @@ fn pack(
fn pack_platform( fn pack_platform(
platform: &Platform, platform: &Platform,
dist_dir: &std::path::PathBuf, dist_dir: &std::path::PathBuf,
pack_files: &Vec<path::PathBuf>, pack_files: &[path::PathBuf],
pack_type: &PackType, pack_type: &PackType,
tar_builder: &mut tar::Builder<File>, tar_builder: &mut tar::Builder<File>,
) -> Result<()> { ) -> Result<()> {
@@ -104,9 +104,7 @@ fn pack_platform(
let full_path = path::Path::new(&base_dir).join(f); let full_path = path::Path::new(&base_dir).join(f);
if !full_path.exists() { if !full_path.exists() {
bail!(error::Error::MissingPackFile( bail!(error::Error::MissingPackFile(
platform.clone(), *platform, *pack_type, full_path,
pack_type.clone(),
full_path,
)); ));
} }
if full_path.is_file() { if full_path.is_file() {
@@ -164,8 +162,11 @@ fn main() -> Result<(), anyhow::Error> {
let compress = !args.is_present("no-compression"); let compress = !args.is_present("no-compression");
let pack_list_str = args let pack_list_str = args
.value_of("packlist") .value_of("packlist")
.map(|f| std::fs::read_to_string(f).expect(&format!("Failed to open packfile {}.", f))) .map(|f| {
.unwrap_or(DEFAULT_PACKLIST.to_string()); std::fs::read_to_string(f)
.unwrap_or_else(|e| panic!("Failed to open packfile {}: {}", f, e))
})
.unwrap_or_else(|| DEFAULT_PACKLIST.to_string());
let pack_list: PackList = let pack_list: PackList =
serde_yaml::from_str(&pack_list_str).expect("Failed to deserialize YAML packlist."); serde_yaml::from_str(&pack_list_str).expect("Failed to deserialize YAML packlist.");
let output_directory = let output_directory =

View File

@@ -9,7 +9,7 @@ use clap::arg_enum;
use std::fmt::{self, Display}; use std::fmt::{self, Display};
arg_enum! { arg_enum! {
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, serde::Deserialize)] #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, serde::Deserialize)]
#[serde(rename_all = "lowercase")] #[serde(rename_all = "lowercase")]
pub enum Platform { pub enum Platform {
Mac, Mac,