tee: avoid unnecessarily cloning argument list

This commit is contained in:
Ben Wiederhake 2024-03-31 16:59:34 +02:00
parent 8ab825c49f
commit 675dd9404a

View file

@ -148,8 +148,7 @@ fn tee(options: &Options) -> Result<()> {
} }
let mut writers: Vec<NamedWriter> = options let mut writers: Vec<NamedWriter> = options
.files .files
.clone() .iter()
.into_iter()
.filter_map(|file| open(file, options.append, options.output_error.as_ref())) .filter_map(|file| open(file, options.append, options.output_error.as_ref()))
.collect::<Result<Vec<NamedWriter>>>()?; .collect::<Result<Vec<NamedWriter>>>()?;
let had_open_errors = writers.len() != options.files.len(); let had_open_errors = writers.len() != options.files.len();
@ -188,11 +187,11 @@ fn tee(options: &Options) -> Result<()> {
/// If that error should lead to program termination, this function returns Some(Err()), /// If that error should lead to program termination, this function returns Some(Err()),
/// otherwise it returns None. /// otherwise it returns None.
fn open( fn open(
name: String, name: &str,
append: bool, append: bool,
output_error: Option<&OutputErrorMode>, output_error: Option<&OutputErrorMode>,
) -> Option<Result<NamedWriter>> { ) -> Option<Result<NamedWriter>> {
let path = PathBuf::from(name.clone()); let path = PathBuf::from(name);
let mut options = OpenOptions::new(); let mut options = OpenOptions::new();
let mode = if append { let mode = if append {
options.append(true) options.append(true)
@ -202,7 +201,7 @@ fn open(
match mode.write(true).create(true).open(path.as_path()) { match mode.write(true).create(true).open(path.as_path()) {
Ok(file) => Some(Ok(NamedWriter { Ok(file) => Some(Ok(NamedWriter {
inner: Box::new(file), inner: Box::new(file),
name, name: name.to_owned(),
})), })),
Err(f) => { Err(f) => {
show_error!("{}: {}", name.maybe_quote(), f); show_error!("{}: {}", name.maybe_quote(), f);