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
@ -9,7 +9,7 @@ fn use_module_file_within_block() {
|
||||
Playground::setup("use_test_1", |dirs, nu| {
|
||||
let file = AbsolutePath::new(dirs.test().join("spam.nu"));
|
||||
|
||||
nu.with_files(vec![FileWithContent(
|
||||
nu.with_files(&[FileWithContent(
|
||||
&file.to_string(),
|
||||
r#"
|
||||
export def foo [] {
|
||||
@ -39,7 +39,7 @@ fn use_keeps_doc_comments() {
|
||||
Playground::setup("use_doc_comments", |dirs, nu| {
|
||||
let file = AbsolutePath::new(dirs.test().join("spam.nu"));
|
||||
|
||||
nu.with_files(vec![FileWithContent(
|
||||
nu.with_files(&[FileWithContent(
|
||||
&file.to_string(),
|
||||
r#"
|
||||
# this is my foo command
|
||||
@ -68,7 +68,7 @@ fn use_keeps_doc_comments() {
|
||||
#[test]
|
||||
fn use_eval_export_env() {
|
||||
Playground::setup("use_eval_export_env", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
||||
sandbox.with_files(&[FileWithContentToBeTrimmed(
|
||||
"spam.nu",
|
||||
r#"
|
||||
export-env { $env.FOO = 'foo' }
|
||||
@ -86,7 +86,7 @@ fn use_eval_export_env() {
|
||||
#[test]
|
||||
fn use_eval_export_env_hide() {
|
||||
Playground::setup("use_eval_export_env", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
||||
sandbox.with_files(&[FileWithContentToBeTrimmed(
|
||||
"spam.nu",
|
||||
r#"
|
||||
export-env { hide-env FOO }
|
||||
@ -106,7 +106,7 @@ fn use_do_cd() {
|
||||
Playground::setup("use_do_cd", |dirs, sandbox| {
|
||||
sandbox
|
||||
.mkdir("test1/test2")
|
||||
.with_files(vec![FileWithContentToBeTrimmed(
|
||||
.with_files(&[FileWithContentToBeTrimmed(
|
||||
"test1/test2/spam.nu",
|
||||
r#"
|
||||
export-env { cd test1/test2 }
|
||||
@ -126,7 +126,7 @@ fn use_do_cd_file_relative() {
|
||||
Playground::setup("use_do_cd_file_relative", |dirs, sandbox| {
|
||||
sandbox
|
||||
.mkdir("test1/test2")
|
||||
.with_files(vec![FileWithContentToBeTrimmed(
|
||||
.with_files(&[FileWithContentToBeTrimmed(
|
||||
"test1/test2/spam.nu",
|
||||
r#"
|
||||
export-env { cd ($env.FILE_PWD | path join '..') }
|
||||
@ -146,7 +146,7 @@ fn use_dont_cd_overlay() {
|
||||
Playground::setup("use_dont_cd_overlay", |dirs, sandbox| {
|
||||
sandbox
|
||||
.mkdir("test1/test2")
|
||||
.with_files(vec![FileWithContentToBeTrimmed(
|
||||
.with_files(&[FileWithContentToBeTrimmed(
|
||||
"test1/test2/spam.nu",
|
||||
r#"
|
||||
export-env {
|
||||
@ -168,7 +168,7 @@ fn use_dont_cd_overlay() {
|
||||
#[test]
|
||||
fn use_export_env_combined() {
|
||||
Playground::setup("use_is_scoped", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
||||
sandbox.with_files(&[FileWithContentToBeTrimmed(
|
||||
"spam.nu",
|
||||
r#"
|
||||
def foo [] { 'foo' }
|
||||
|
Reference in New Issue
Block a user