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

@ -8,7 +8,7 @@ mod simple {
#[test]
fn extracts_fields_from_the_given_the_pattern() {
Playground::setup("parse_test_1", |dirs, sandbox| {
sandbox.with_files(vec![Stub::FileWithContentToBeTrimmed(
sandbox.with_files(&[Stub::FileWithContentToBeTrimmed(
"key_value_separated_arepa_ingredients.txt",
r#"
VAR1=Cheese
@ -117,7 +117,7 @@ mod regex {
#[test]
fn extracts_fields_with_all_named_groups() {
Playground::setup("parse_test_regex_1", |dirs, sandbox| {
sandbox.with_files(nushell_git_log_oneline());
sandbox.with_files(&nushell_git_log_oneline());
let actual = nu!(
cwd: dirs.test(), pipeline(
@ -136,7 +136,7 @@ mod regex {
#[test]
fn extracts_fields_with_all_unnamed_groups() {
Playground::setup("parse_test_regex_2", |dirs, sandbox| {
sandbox.with_files(nushell_git_log_oneline());
sandbox.with_files(&nushell_git_log_oneline());
let actual = nu!(
cwd: dirs.test(), pipeline(
@ -155,7 +155,7 @@ mod regex {
#[test]
fn extracts_fields_with_named_and_unnamed_groups() {
Playground::setup("parse_test_regex_3", |dirs, sandbox| {
sandbox.with_files(nushell_git_log_oneline());
sandbox.with_files(&nushell_git_log_oneline());
let actual = nu!(
cwd: dirs.test(), pipeline(
@ -174,7 +174,7 @@ mod regex {
#[test]
fn errors_with_invalid_regex() {
Playground::setup("parse_test_regex_1", |dirs, sandbox| {
sandbox.with_files(nushell_git_log_oneline());
sandbox.with_files(&nushell_git_log_oneline());
let actual = nu!(
cwd: dirs.test(), pipeline(
@ -216,7 +216,7 @@ mod regex {
fn parse_handles_external_stream_chunking() {
Playground::setup("parse_test_streaming_1", |dirs, sandbox| {
let data: String = "abcdefghijklmnopqrstuvwxyz".repeat(1000);
sandbox.with_files(vec![Stub::FileWithContent("data.txt", &data)]);
sandbox.with_files(&[Stub::FileWithContent("data.txt", &data)]);
let actual = nu!(
cwd: dirs.test(),