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:
Stefan Holderbach
2024-05-04 02:53:15 +02:00
committed by GitHub
parent e6f473695c
commit 406df7f208
69 changed files with 527 additions and 553 deletions

View File

@ -129,7 +129,7 @@ fn passes_with_env_env_var_to_external_process() {
#[test]
fn has_file_pwd() {
Playground::setup("has_file_pwd", |dirs, sandbox| {
sandbox.with_files(vec![FileWithContent("spam.nu", "$env.FILE_PWD")]);
sandbox.with_files(&[FileWithContent("spam.nu", "$env.FILE_PWD")]);
let actual = nu!(cwd: dirs.test(), "nu spam.nu");
@ -140,7 +140,7 @@ fn has_file_pwd() {
#[test]
fn has_file_loc() {
Playground::setup("has_file_pwd", |dirs, sandbox| {
sandbox.with_files(vec![FileWithContent("spam.nu", "$env.CURRENT_FILE")]);
sandbox.with_files(&[FileWithContent("spam.nu", "$env.CURRENT_FILE")]);
let actual = nu!(cwd: dirs.test(), "nu spam.nu");
@ -154,7 +154,7 @@ fn has_file_loc() {
#[serial]
fn passes_env_from_local_cfg_to_external_process() {
Playground::setup("autoenv_dir", |dirs, sandbox| {
sandbox.with_files(vec![FileWithContent(
sandbox.with_files(&[FileWithContent(
".nu-env",
r#"[env]
FOO = "foo"