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

@ -7,7 +7,7 @@ use std::path::{Path, PathBuf};
#[test]
fn empty_glob_pattern_triggers_error() {
Playground::setup("glob_test_1", |dirs, sandbox| {
sandbox.with_files(vec![
sandbox.with_files(&[
EmptyFile("yehuda.txt"),
EmptyFile("jttxt"),
EmptyFile("andres.txt"),
@ -25,7 +25,7 @@ fn empty_glob_pattern_triggers_error() {
#[test]
fn nonempty_glob_lists_matching_paths() {
Playground::setup("glob_sanity_star", |dirs, sandbox| {
sandbox.with_files(vec![
sandbox.with_files(&[
EmptyFile("yehuda.txt"),
EmptyFile("jttxt"),
EmptyFile("andres.txt"),
@ -43,13 +43,13 @@ fn nonempty_glob_lists_matching_paths() {
#[test]
fn glob_subdirs() {
Playground::setup("glob_subdirs", |dirs, sandbox| {
sandbox.with_files(vec![
sandbox.with_files(&[
EmptyFile("yehuda.txt"),
EmptyFile("jttxt"),
EmptyFile("andres.txt"),
]);
sandbox.mkdir("children");
sandbox.within("children").with_files(vec![
sandbox.within("children").with_files(&[
EmptyFile("timothy.txt"),
EmptyFile("tiffany.txt"),
EmptyFile("trish.txt"),
@ -70,13 +70,13 @@ fn glob_subdirs() {
#[test]
fn glob_subdirs_ignore_dirs() {
Playground::setup("glob_subdirs_ignore_directories", |dirs, sandbox| {
sandbox.with_files(vec![
sandbox.with_files(&[
EmptyFile("yehuda.txt"),
EmptyFile("jttxt"),
EmptyFile("andres.txt"),
]);
sandbox.mkdir("children");
sandbox.within("children").with_files(vec![
sandbox.within("children").with_files(&[
EmptyFile("timothy.txt"),
EmptyFile("tiffany.txt"),
EmptyFile("trish.txt"),
@ -97,13 +97,13 @@ fn glob_subdirs_ignore_dirs() {
#[test]
fn glob_ignore_files() {
Playground::setup("glob_ignore_files", |dirs, sandbox| {
sandbox.with_files(vec![
sandbox.with_files(&[
EmptyFile("yehuda.txt"),
EmptyFile("jttxt"),
EmptyFile("andres.txt"),
]);
sandbox.mkdir("children");
sandbox.within("children").with_files(vec![
sandbox.within("children").with_files(&[
EmptyFile("timothy.txt"),
EmptyFile("tiffany.txt"),
EmptyFile("trish.txt"),