Skip to content

Commit

Permalink
tee: avoid unnecessarily cloning argument list
Browse files Browse the repository at this point in the history
  • Loading branch information
BenWiederhake committed Mar 31, 2024
1 parent 8ab825c commit 675dd94
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/uu/tee/src/tee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,7 @@ fn tee(options: &Options) -> Result<()> {
}
let mut writers: Vec<NamedWriter> = options
.files
.clone()
.into_iter()
.iter()
.filter_map(|file| open(file, options.append, options.output_error.as_ref()))
.collect::<Result<Vec<NamedWriter>>>()?;
let had_open_errors = writers.len() != options.files.len();
Expand Down Expand Up @@ -188,11 +187,11 @@ fn tee(options: &Options) -> Result<()> {
/// If that error should lead to program termination, this function returns Some(Err()),
/// otherwise it returns None.
fn open(
name: String,
name: &str,
append: bool,
output_error: Option<&OutputErrorMode>,
) -> Option<Result<NamedWriter>> {
let path = PathBuf::from(name.clone());
let path = PathBuf::from(name);
let mut options = OpenOptions::new();
let mode = if append {
options.append(true)
Expand All @@ -202,7 +201,7 @@ fn open(
match mode.write(true).create(true).open(path.as_path()) {
Ok(file) => Some(Ok(NamedWriter {
inner: Box::new(file),
name,
name: name.to_owned(),
})),
Err(f) => {
show_error!("{}: {}", name.maybe_quote(), f);
Expand Down

0 comments on commit 675dd94

Please sign in to comment.