From 6a23f77687ad6e0ff7e50daf42e3a4e73505c180 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fe=CC=81lix=20Saparelli?= Date: Sat, 26 Jan 2019 17:20:29 +1300 Subject: [PATCH] [run] Pass ops by reference when possible --- src/process.rs | 10 +++++----- src/run.rs | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/process.rs b/src/process.rs index 02495019..0ead6815 100644 --- a/src/process.rs +++ b/src/process.rs @@ -2,7 +2,7 @@ use pathop::PathOp; use std::collections::{HashMap, HashSet}; use std::path::PathBuf; -pub fn spawn(cmd: &Vec, updated_paths: Vec, no_shell: bool) -> Process { +pub fn spawn(cmd: &Vec, updated_paths: &[PathOp], no_shell: bool) -> Process { self::imp::Process::new(cmd, updated_paths, no_shell).expect("unable to spawn process") } @@ -83,7 +83,7 @@ mod imp { impl Process { pub fn new( cmd: &Vec, - updated_paths: Vec, + updated_paths: &[PathOp], no_shell: bool, ) -> Result { use nix::unistd::*; @@ -108,7 +108,7 @@ mod imp { debug!("Assembled command {:?}", command); - let command_envs = super::collect_path_env_vars(&updated_paths); + let command_envs = super::collect_path_env_vars(updated_paths); for &(ref name, ref val) in &command_envs { command.env(name, val); } @@ -204,7 +204,7 @@ mod imp { impl Process { pub fn new( cmd: &Vec, - updated_paths: Vec, + updated_paths: &[PathOp], no_shell: bool, ) -> Result { use std::os::windows::io::IntoRawHandle; @@ -276,7 +276,7 @@ mod imp { command.creation_flags(CREATE_SUSPENDED); debug!("Assembled command {:?}", command); - let command_envs = super::collect_path_env_vars(&updated_paths); + let command_envs = super::collect_path_env_vars(updated_paths); for &(ref name, ref val) in &command_envs { command.env(name, val); } diff --git a/src/run.rs b/src/run.rs index 4c8e0e07..a99d7eef 100644 --- a/src/run.rs +++ b/src/run.rs @@ -64,7 +64,7 @@ pub trait Handler { /// - `Err`: an error has occurred while processing, quit. /// - `Ok(true)`: everything is fine and the loop can continue. /// - `Ok(false)`: everything is fine but we should gracefully stop. - fn on_update(&mut self, ops: Vec) -> Result; + fn on_update(&mut self, ops: &[PathOp]) -> Result; } /// Starts watching, and calls a handler when something happens. @@ -133,7 +133,7 @@ where clear_screen(); } - if !handler.on_update(paths)? { + if !handler.on_update(&paths)? { break; } } @@ -148,7 +148,7 @@ pub struct ExecHandler { } impl ExecHandler { - fn spawn(&mut self, ops: Vec) -> Result<()> { + fn spawn(&mut self, ops: &[PathOp]) -> Result<()> { let mut guard = self.child_process.write()?; *guard = Some(process::spawn( &self.args.cmd, @@ -189,11 +189,11 @@ impl Handler for ExecHandler { // Only returns Err() on lock poisoning. fn on_manual(&mut self) -> Result { - self.spawn(Vec::new()).and(Ok(true)) + self.spawn(&[]).and(Ok(true)) } // Only returns Err() on lock poisoning. - fn on_update(&mut self, ops: Vec) -> Result { + fn on_update(&mut self, ops: &[PathOp]) -> Result { // We have three scenarios here: // // 1. Make sure the previous run was ended, then run the command again