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
@ -50,7 +50,7 @@ fn from_string() {
|
||||
#[test]
|
||||
fn from_filename() {
|
||||
Playground::setup("from_filename", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
||||
sandbox.with_files(&[FileWithContentToBeTrimmed(
|
||||
"sample.toml",
|
||||
r#"
|
||||
[dependency]
|
||||
@ -70,7 +70,7 @@ fn from_filename() {
|
||||
#[test]
|
||||
fn from_filesize() {
|
||||
Playground::setup("from_filesize", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
||||
sandbox.with_files(&[FileWithContentToBeTrimmed(
|
||||
"sample.toml",
|
||||
r#"
|
||||
[dependency]
|
||||
|
@ -8,7 +8,7 @@ use nu_test_support::{nu, pipeline};
|
||||
#[test]
|
||||
fn trims() {
|
||||
Playground::setup("str_test_1", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContent(
|
||||
sandbox.with_files(&[FileWithContent(
|
||||
"sample.toml",
|
||||
r#"
|
||||
[dependency]
|
||||
@ -39,7 +39,7 @@ fn error_trim_multiple_chars() {
|
||||
#[test]
|
||||
fn capitalizes() {
|
||||
Playground::setup("str_test_2", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContent(
|
||||
sandbox.with_files(&[FileWithContent(
|
||||
"sample.toml",
|
||||
r#"
|
||||
[dependency]
|
||||
@ -59,7 +59,7 @@ fn capitalizes() {
|
||||
#[test]
|
||||
fn downcases() {
|
||||
Playground::setup("str_test_3", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContent(
|
||||
sandbox.with_files(&[FileWithContent(
|
||||
"sample.toml",
|
||||
r#"
|
||||
[dependency]
|
||||
@ -86,7 +86,7 @@ fn non_ascii_downcase() {
|
||||
#[test]
|
||||
fn upcases() {
|
||||
Playground::setup("str_test_4", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContent(
|
||||
sandbox.with_files(&[FileWithContent(
|
||||
"sample.toml",
|
||||
r#"
|
||||
[package]
|
||||
@ -114,7 +114,7 @@ fn non_ascii_upcase() {
|
||||
#[ignore = "Playgrounds are not supported in nu-cmd-extra"]
|
||||
fn camelcases() {
|
||||
Playground::setup("str_test_3", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContent(
|
||||
sandbox.with_files(&[FileWithContent(
|
||||
"sample.toml",
|
||||
r#"
|
||||
[dependency]
|
||||
@ -165,7 +165,7 @@ fn converts_to_float() {
|
||||
#[test]
|
||||
fn find_and_replaces() {
|
||||
Playground::setup("str_test_6", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContent(
|
||||
sandbox.with_files(&[FileWithContent(
|
||||
"sample.toml",
|
||||
r#"
|
||||
[fortune.teller]
|
||||
@ -189,7 +189,7 @@ fn find_and_replaces() {
|
||||
#[test]
|
||||
fn find_and_replaces_without_passing_field() {
|
||||
Playground::setup("str_test_7", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContent(
|
||||
sandbox.with_files(&[FileWithContent(
|
||||
"sample.toml",
|
||||
r#"
|
||||
[fortune.teller]
|
||||
@ -233,7 +233,7 @@ fn regex_error_in_pattern() {
|
||||
#[test]
|
||||
fn substrings_the_input() {
|
||||
Playground::setup("str_test_8", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContent(
|
||||
sandbox.with_files(&[FileWithContent(
|
||||
"sample.toml",
|
||||
r#"
|
||||
[fortune.teller]
|
||||
@ -257,7 +257,7 @@ fn substrings_the_input() {
|
||||
#[test]
|
||||
fn substring_errors_if_start_index_is_greater_than_end_index() {
|
||||
Playground::setup("str_test_9", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContent(
|
||||
sandbox.with_files(&[FileWithContent(
|
||||
"sample.toml",
|
||||
r#"
|
||||
[fortune.teller]
|
||||
@ -282,7 +282,7 @@ fn substring_errors_if_start_index_is_greater_than_end_index() {
|
||||
#[test]
|
||||
fn substrings_the_input_and_returns_the_string_if_end_index_exceeds_length() {
|
||||
Playground::setup("str_test_10", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContent(
|
||||
sandbox.with_files(&[FileWithContent(
|
||||
"sample.toml",
|
||||
r#"
|
||||
[package]
|
||||
@ -306,7 +306,7 @@ fn substrings_the_input_and_returns_the_string_if_end_index_exceeds_length() {
|
||||
#[test]
|
||||
fn substrings_the_input_and_returns_blank_if_start_index_exceeds_length() {
|
||||
Playground::setup("str_test_11", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContent(
|
||||
sandbox.with_files(&[FileWithContent(
|
||||
"sample.toml",
|
||||
r#"
|
||||
[package]
|
||||
@ -330,7 +330,7 @@ fn substrings_the_input_and_returns_blank_if_start_index_exceeds_length() {
|
||||
#[test]
|
||||
fn substrings_the_input_and_treats_start_index_as_zero_if_blank_start_index_given() {
|
||||
Playground::setup("str_test_12", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContent(
|
||||
sandbox.with_files(&[FileWithContent(
|
||||
"sample.toml",
|
||||
r#"
|
||||
[package]
|
||||
@ -354,7 +354,7 @@ fn substrings_the_input_and_treats_start_index_as_zero_if_blank_start_index_give
|
||||
#[test]
|
||||
fn substrings_the_input_and_treats_end_index_as_length_if_blank_end_index_given() {
|
||||
Playground::setup("str_test_13", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContent(
|
||||
sandbox.with_files(&[FileWithContent(
|
||||
"sample.toml",
|
||||
r#"
|
||||
[package]
|
||||
|
Reference in New Issue
Block a user