mirror of
https://github.com/nushell/nushell.git
synced 2025-06-30 14:40:06 +02:00
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
@ -93,7 +93,7 @@ fn parse_file_relative_to_parsed_file_simple() {
|
||||
sandbox
|
||||
.mkdir("lol")
|
||||
.mkdir("lol/lol")
|
||||
.with_files(vec![FileWithContentToBeTrimmed(
|
||||
.with_files(&[FileWithContentToBeTrimmed(
|
||||
"lol/lol/lol.nu",
|
||||
"
|
||||
use ../lol_shell.nu
|
||||
@ -101,7 +101,7 @@ fn parse_file_relative_to_parsed_file_simple() {
|
||||
$env.LOL = (lol_shell ls)
|
||||
",
|
||||
)])
|
||||
.with_files(vec![FileWithContentToBeTrimmed(
|
||||
.with_files(&[FileWithContentToBeTrimmed(
|
||||
"lol/lol_shell.nu",
|
||||
r#"
|
||||
export def ls [] { "lol" }
|
||||
@ -123,7 +123,7 @@ fn parse_file_relative_to_parsed_file_simple() {
|
||||
#[test]
|
||||
fn predecl_signature_single_inp_out_type() {
|
||||
Playground::setup("predecl_signature_single_inp_out_type", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
||||
sandbox.with_files(&[FileWithContentToBeTrimmed(
|
||||
"spam1.nu",
|
||||
"
|
||||
def main [] { foo }
|
||||
@ -143,7 +143,7 @@ fn predecl_signature_multiple_inp_out_types() {
|
||||
Playground::setup(
|
||||
"predecl_signature_multiple_inp_out_types",
|
||||
|dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
||||
sandbox.with_files(&[FileWithContentToBeTrimmed(
|
||||
"spam2.nu",
|
||||
"
|
||||
def main [] { foo }
|
||||
@ -166,7 +166,7 @@ fn parse_file_relative_to_parsed_file() {
|
||||
sandbox
|
||||
.mkdir("lol")
|
||||
.mkdir("lol/lol")
|
||||
.with_files(vec![FileWithContentToBeTrimmed(
|
||||
.with_files(&[FileWithContentToBeTrimmed(
|
||||
"lol/lol/lol.nu",
|
||||
"
|
||||
source-env ../../foo.nu
|
||||
@ -176,13 +176,13 @@ fn parse_file_relative_to_parsed_file() {
|
||||
$env.LOL = $'($env.FOO) (lol_shell ls) (ls)'
|
||||
",
|
||||
)])
|
||||
.with_files(vec![FileWithContentToBeTrimmed(
|
||||
.with_files(&[FileWithContentToBeTrimmed(
|
||||
"lol/lol_shell.nu",
|
||||
r#"
|
||||
export def ls [] { "lol" }
|
||||
"#,
|
||||
)])
|
||||
.with_files(vec![FileWithContentToBeTrimmed(
|
||||
.with_files(&[FileWithContentToBeTrimmed(
|
||||
"foo.nu",
|
||||
"
|
||||
$env.FOO = 'foo'
|
||||
@ -206,19 +206,19 @@ fn parse_file_relative_to_parsed_file_dont_use_cwd_1() {
|
||||
Playground::setup("relative_files", |dirs, sandbox| {
|
||||
sandbox
|
||||
.mkdir("lol")
|
||||
.with_files(vec![FileWithContentToBeTrimmed(
|
||||
.with_files(&[FileWithContentToBeTrimmed(
|
||||
"lol/lol.nu",
|
||||
"
|
||||
source-env foo.nu
|
||||
",
|
||||
)])
|
||||
.with_files(vec![FileWithContentToBeTrimmed(
|
||||
.with_files(&[FileWithContentToBeTrimmed(
|
||||
"lol/foo.nu",
|
||||
"
|
||||
$env.FOO = 'good'
|
||||
",
|
||||
)])
|
||||
.with_files(vec![FileWithContentToBeTrimmed(
|
||||
.with_files(&[FileWithContentToBeTrimmed(
|
||||
"foo.nu",
|
||||
"
|
||||
$env.FOO = 'bad'
|
||||
@ -242,13 +242,13 @@ fn parse_file_relative_to_parsed_file_dont_use_cwd_2() {
|
||||
Playground::setup("relative_files", |dirs, sandbox| {
|
||||
sandbox
|
||||
.mkdir("lol")
|
||||
.with_files(vec![FileWithContentToBeTrimmed(
|
||||
.with_files(&[FileWithContentToBeTrimmed(
|
||||
"lol/lol.nu",
|
||||
"
|
||||
source-env foo.nu
|
||||
",
|
||||
)])
|
||||
.with_files(vec![FileWithContentToBeTrimmed(
|
||||
.with_files(&[FileWithContentToBeTrimmed(
|
||||
"foo.nu",
|
||||
"
|
||||
$env.FOO = 'bad'
|
||||
|
Reference in New Issue
Block a user