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

@ -26,7 +26,7 @@ fn chooses_highest_increment_if_given_more_than_one() {
#[test]
fn by_one_with_field_passed() {
Playground::setup("plugin_inc_test_1", |dirs, sandbox| {
sandbox.with_files(vec![FileWithContent(
sandbox.with_files(&[FileWithContent(
"sample.toml",
r#"
[package]
@ -47,7 +47,7 @@ fn by_one_with_field_passed() {
#[test]
fn by_one_with_no_field_passed() {
Playground::setup("plugin_inc_test_2", |dirs, sandbox| {
sandbox.with_files(vec![FileWithContent(
sandbox.with_files(&[FileWithContent(
"sample.toml",
r#"
[package]
@ -68,7 +68,7 @@ fn by_one_with_no_field_passed() {
#[test]
fn semversion_major_inc() {
Playground::setup("plugin_inc_test_3", |dirs, sandbox| {
sandbox.with_files(vec![FileWithContent(
sandbox.with_files(&[FileWithContent(
"sample.toml",
r#"
[package]
@ -89,7 +89,7 @@ fn semversion_major_inc() {
#[test]
fn semversion_minor_inc() {
Playground::setup("plugin_inc_test_4", |dirs, sandbox| {
sandbox.with_files(vec![FileWithContent(
sandbox.with_files(&[FileWithContent(
"sample.toml",
r#"
[package]
@ -110,7 +110,7 @@ fn semversion_minor_inc() {
#[test]
fn semversion_patch_inc() {
Playground::setup("plugin_inc_test_5", |dirs, sandbox| {
sandbox.with_files(vec![FileWithContent(
sandbox.with_files(&[FileWithContent(
"sample.toml",
r#"
[package]
@ -131,7 +131,7 @@ fn semversion_patch_inc() {
#[test]
fn semversion_without_passing_field() {
Playground::setup("plugin_inc_test_6", |dirs, sandbox| {
sandbox.with_files(vec![FileWithContent(
sandbox.with_files(&[FileWithContent(
"sample.toml",
r#"
[package]

View File

@ -6,7 +6,7 @@ use pretty_assertions::assert_eq;
#[test]
fn infers_types() {
Playground::setup("filter_from_ics_test_1", |dirs, sandbox| {
sandbox.with_files(vec![FileWithContentToBeTrimmed(
sandbox.with_files(&[FileWithContentToBeTrimmed(
"calendar.ics",
r#"
BEGIN:VCALENDAR
@ -58,7 +58,7 @@ fn infers_types() {
#[test]
fn from_ics_text_to_table() {
Playground::setup("filter_from_ics_test_2", |dirs, sandbox| {
sandbox.with_files(vec![FileWithContentToBeTrimmed(
sandbox.with_files(&[FileWithContentToBeTrimmed(
"calendar.txt",
r#"
BEGIN:VCALENDAR
@ -102,7 +102,7 @@ fn from_ics_text_to_table() {
#[test]
fn from_ics_text_with_linebreak_to_table() {
Playground::setup("filter_from_ics_test_3", |dirs, sandbox| {
sandbox.with_files(vec![FileWithContent(
sandbox.with_files(&[FileWithContent(
"calendar.txt",
r#"BEGIN:VCALENDAR
BEGIN:VEVENT

View File

@ -33,7 +33,7 @@ fn parses_utf16_ini() {
#[test]
fn read_ini_with_missing_session() {
Playground::setup("from ini with missiong session", |dirs, sandbox| {
sandbox.with_files(vec![FileWithContentToBeTrimmed(
sandbox.with_files(&[FileWithContentToBeTrimmed(
"some_missing.ini",
r#"
min-width=450

View File

@ -6,7 +6,7 @@ use pretty_assertions::assert_eq;
#[test]
fn infers_types() {
Playground::setup("filter_from_vcf_test_1", |dirs, sandbox| {
sandbox.with_files(vec![FileWithContentToBeTrimmed(
sandbox.with_files(&[FileWithContentToBeTrimmed(
"contacts.vcf",
r"
BEGIN:VCARD
@ -46,7 +46,7 @@ fn infers_types() {
#[test]
fn from_vcf_text_to_table() {
Playground::setup("filter_from_vcf_test_2", |dirs, sandbox| {
sandbox.with_files(vec![FileWithContentToBeTrimmed(
sandbox.with_files(&[FileWithContentToBeTrimmed(
"contacts.txt",
r"
BEGIN:VCARD
@ -86,7 +86,7 @@ fn from_vcf_text_to_table() {
#[test]
fn from_vcf_text_with_linebreak_to_table() {
Playground::setup("filter_from_vcf_test_3", |dirs, sandbox| {
sandbox.with_files(vec![FileWithContent(
sandbox.with_files(&[FileWithContent(
"contacts.txt",
r"BEGIN:VCARD
VERSION:3.0

View File

@ -136,7 +136,7 @@ fn plugin_add_to_custom_path() {
fn plugin_rm_then_restart_nu() {
let example_plugin_path = example_plugin_path();
Playground::setup("plugin rm from custom path", |dirs, playground| {
playground.with_files(vec![
playground.with_files(&[
Stub::FileWithContent("config.nu", ""),
Stub::FileWithContent("env.nu", ""),
]);
@ -318,7 +318,7 @@ fn plugin_rm_using_filename() {
fn warning_on_invalid_plugin_item() {
let example_plugin_path = example_plugin_path();
Playground::setup("warning on invalid plugin item", |dirs, playground| {
playground.with_files(vec![
playground.with_files(&[
Stub::FileWithContent("config.nu", ""),
Stub::FileWithContent("env.nu", ""),
]);
@ -380,7 +380,7 @@ fn warning_on_invalid_plugin_item() {
#[test]
fn plugin_use_error_not_found() {
Playground::setup("plugin use error not found", |dirs, playground| {
playground.with_files(vec![
playground.with_files(&[
Stub::FileWithContent("config.nu", ""),
Stub::FileWithContent("env.nu", ""),
]);