forked from extern/nushell
Avoid taking unnecessary ownership of intermediates (#12740)
# Description Judiciously try to avoid allocations/clone by changing the signature of functions - **Don't pass str by value unnecessarily if only read** - **Don't require a vec in `Sandbox::with_files`** - **Remove unnecessary string clone** - **Fixup unnecessary borrow** - **Use `&str` in shape color instead** - **Vec -> Slice** - **Elide string clone** - **Elide `Path` clone** - **Take &str to elide clone in tests** # User-Facing Changes None # Tests + Formatting This touches many tests purely in changing from owned to borrowed/static data
This commit is contained in:
committed by
GitHub
parent
e6f473695c
commit
406df7f208
@ -284,7 +284,7 @@ pub fn nu_run_test(opts: NuOpts, commands: impl AsRef<str>, with_std: bool) -> O
|
||||
command.arg("--no-std-lib");
|
||||
}
|
||||
command
|
||||
.arg(format!("-c {}", escape_quote_string(commands)))
|
||||
.arg(format!("-c {}", escape_quote_string(&commands)))
|
||||
.stdout(Stdio::piped())
|
||||
.stderr(Stdio::piped());
|
||||
|
||||
@ -353,7 +353,7 @@ where
|
||||
let plugin_path = nu_path::canonicalize_with(&plugin, &test_bins)
|
||||
.unwrap_or_else(|_| panic!("failed to canonicalize plugin {} path", &plugin));
|
||||
let plugin_path = plugin_path.to_string_lossy();
|
||||
escape_quote_string(plugin_path.into_owned())
|
||||
escape_quote_string(&plugin_path)
|
||||
})
|
||||
.collect();
|
||||
let plugins_arg = format!("[{}]", plugin_paths_quoted.join(","));
|
||||
@ -397,7 +397,7 @@ where
|
||||
Outcome::new(out, err.into_owned(), output.status)
|
||||
}
|
||||
|
||||
fn escape_quote_string(input: String) -> String {
|
||||
fn escape_quote_string(input: &str) -> String {
|
||||
let mut output = String::with_capacity(input.len() + 2);
|
||||
output.push('"');
|
||||
|
||||
|
@ -199,7 +199,7 @@ impl<'a> Playground<'a> {
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_files(&mut self, files: Vec<Stub>) -> &mut Self {
|
||||
pub fn with_files(&mut self, files: &[Stub]) -> &mut Self {
|
||||
let endl = fs::line_ending();
|
||||
|
||||
files
|
||||
|
Reference in New Issue
Block a user