Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: Introduce RcStr #8221

Merged
merged 330 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
330 commits
Select commit Hold shift + click to select a range
ae16e99
fix more
kdy1 May 29, 2024
d833a2f
fix more
kdy1 May 29, 2024
cf6f60e
fix more
kdy1 May 29, 2024
71d8eee
fix more
kdy1 May 29, 2024
c705e4d
fix more
kdy1 May 29, 2024
0940061
fix more
kdy1 May 29, 2024
6ae9a77
fix more
kdy1 May 29, 2024
04ed6ce
Optimize From impl for File
kdy1 May 29, 2024
68bc6d1
More fix
kdy1 May 29, 2024
8f6b2fe
More fix
kdy1 May 29, 2024
756fa60
More fix
kdy1 May 29, 2024
574d22f
impl DeterministicHash for RcStr
kdy1 May 29, 2024
420fa65
More fix
kdy1 May 29, 2024
e401706
More fix
kdy1 May 29, 2024
f0f4c14
More fix
kdy1 May 29, 2024
815c412
More fix
kdy1 May 29, 2024
5b732bf
More fix
kdy1 May 29, 2024
0b7d63c
More fix
kdy1 May 29, 2024
c0fc8d2
More fix
kdy1 May 29, 2024
d9c2792
More fix
kdy1 May 29, 2024
c50e67d
More fix
kdy1 May 29, 2024
2d94902
More fix
kdy1 May 29, 2024
bff91b6
impl From<String> for File
kdy1 May 29, 2024
fb7d479
Fix more
kdy1 May 29, 2024
35e7377
Fix more
kdy1 May 29, 2024
9a2e1ca
Fix more
kdy1 May 29, 2024
9564647
Fix more
kdy1 May 29, 2024
92e7d1e
Fix more
kdy1 May 29, 2024
684ddf1
Fix more
kdy1 May 29, 2024
980fdb0
Fix more
kdy1 May 29, 2024
d279ac9
Fix more
kdy1 May 29, 2024
877d823
Fix more
kdy1 May 29, 2024
6937818
Fix more
kdy1 May 29, 2024
3e88ced
Fix more
kdy1 May 29, 2024
7cbc8c1
Fix more
kdy1 May 29, 2024
fbc7a68
Fix more
kdy1 May 29, 2024
c8b3260
Fix more
kdy1 May 29, 2024
61a0032
Fix more
kdy1 May 29, 2024
0a099e6
Fix more
kdy1 May 29, 2024
e885cae
Fix more
kdy1 May 29, 2024
7ea56a4
Fix more
kdy1 May 29, 2024
e007b93
Fix more
kdy1 May 29, 2024
0af33fb
Fix more
kdy1 May 29, 2024
7f6cd33
Fix more
kdy1 May 29, 2024
83b2169
Fix more
kdy1 May 29, 2024
d8a361a
Fix more
kdy1 May 29, 2024
672164d
Fix more
kdy1 May 29, 2024
f5ecdd4
Fix more
kdy1 May 29, 2024
bc45214
Fix more
kdy1 May 29, 2024
b39d299
Fix more
kdy1 May 29, 2024
db606f5
Fix more
kdy1 May 29, 2024
06d85c7
Fix more
kdy1 May 29, 2024
d9b814b
Fix more
kdy1 May 30, 2024
9920216
Fix more
kdy1 May 30, 2024
e35d615
Fix more
kdy1 May 30, 2024
d13bc0a
Fix more
kdy1 May 30, 2024
a3edac7
Fix more
kdy1 May 30, 2024
1ecbc6e
Fix more
kdy1 May 30, 2024
15c613d
Fix more
kdy1 May 30, 2024
b0c1e4c
Fix more
kdy1 May 30, 2024
1485637
Fix more
kdy1 May 30, 2024
b5e31a1
Fix more
kdy1 May 30, 2024
cbb678f
Fix more
kdy1 May 30, 2024
0bc77b0
Fix more
kdy1 May 30, 2024
8900572
Fix more
kdy1 May 30, 2024
78426e9
Fix more
kdy1 May 30, 2024
bb43782
Fix more
kdy1 May 30, 2024
b2e6cf5
Fix more
kdy1 May 30, 2024
205dcf7
Fix more
kdy1 May 30, 2024
93c8b71
Fix more
kdy1 May 30, 2024
d647d37
Fix more
kdy1 May 30, 2024
d7456ec
Fix more
kdy1 May 30, 2024
185e1ff
Fix more
kdy1 May 30, 2024
364779d
Fix more
kdy1 May 30, 2024
e325fa4
Fix more
kdy1 May 30, 2024
2fe3fce
Fix more
kdy1 May 30, 2024
9451be4
impl more traits
kdy1 May 30, 2024
d298ccc
Fix more
kdy1 May 31, 2024
893e1e1
Fix more
kdy1 May 31, 2024
84abbab
Fix more
kdy1 May 31, 2024
d0ef537
Fix more
kdy1 May 31, 2024
c64a36d
Fix more
kdy1 May 31, 2024
06eb89a
Fix more
kdy1 May 31, 2024
9c62c84
Fix more
kdy1 May 31, 2024
d2efbd2
Fix more
kdy1 May 31, 2024
7dc9748
Fix more
kdy1 May 31, 2024
77e182f
Fix more
kdy1 May 31, 2024
8d0912f
Fix more
kdy1 May 31, 2024
c14283a
Fix more
kdy1 May 31, 2024
2f2a717
Fix more
kdy1 May 31, 2024
8d33aed
Fix more
kdy1 May 31, 2024
16aefc9
Fix more
kdy1 May 31, 2024
6335004
Fix more
kdy1 May 31, 2024
0532756
Fix more
kdy1 May 31, 2024
d183a5a
Fix more
kdy1 May 31, 2024
5b43dfb
Fix more
kdy1 May 31, 2024
7f2ee29
Fix more
kdy1 May 31, 2024
122ae36
Fix more
kdy1 May 31, 2024
3e75dcc
Fix more
kdy1 May 31, 2024
b33cb89
Fix more
kdy1 May 31, 2024
ee4ba45
Fix more
kdy1 May 31, 2024
9d00aaa
Fix more
kdy1 May 31, 2024
99e3881
Fix more
kdy1 May 31, 2024
cc87ac0
Fix more
kdy1 May 31, 2024
773bc5b
Fix more
kdy1 May 31, 2024
9b92f5a
Fix more
kdy1 Jun 1, 2024
88c1c60
__turbo_tasks_internal_primitive!(RcStr);
kdy1 Jun 1, 2024
c06738e
Fix more
kdy1 Jun 1, 2024
a286da2
Fix more
kdy1 Jun 1, 2024
71c111f
fix more
kdy1 Jun 1, 2024
3e25108
fix more
kdy1 Jun 1, 2024
2392077
fix more
kdy1 Jun 1, 2024
ade05cc
fix more
kdy1 Jun 1, 2024
b8a592b
fix more
kdy1 Jun 1, 2024
11463d8
Replace
kdy1 Jun 3, 2024
d98eac8
Replace
kdy1 Jun 3, 2024
8a27f54
Replace
kdy1 Jun 3, 2024
5e74062
Primitive
kdy1 Jun 3, 2024
3a7ac37
Replace
kdy1 Jun 3, 2024
161ded8
Fix more
kdy1 Jun 3, 2024
2f1b314
Fix more
kdy1 Jun 3, 2024
d2aa33f
Fix more
kdy1 Jun 3, 2024
259fb78
Replace
kdy1 Jun 3, 2024
c7df8a2
Fix more
kdy1 Jun 3, 2024
13d70bf
Fix more
kdy1 Jun 3, 2024
1167ab8
Fix more
kdy1 Jun 3, 2024
f6b25a3
Fix more
kdy1 Jun 3, 2024
ef43b2e
Fix more
kdy1 Jun 3, 2024
22246ea
Fix more
kdy1 Jun 3, 2024
ba15f09
Fix more
kdy1 Jun 3, 2024
b37a99b
Fix more
kdy1 Jun 3, 2024
06bd595
Fix more
kdy1 Jun 3, 2024
d96d4ed
Fix more
kdy1 Jun 3, 2024
9bb6365
Fix more
kdy1 Jun 3, 2024
5285e1b
Replace: ReadRef<String>
kdy1 Jun 3, 2024
14842bf
Fix more
kdy1 Jun 3, 2024
06bb1f1
Fix more
kdy1 Jun 3, 2024
0b1702c
Fix more
kdy1 Jun 3, 2024
aaee0c4
Fix more
kdy1 Jun 3, 2024
c6032e7
Fix more
kdy1 Jun 3, 2024
ea05f8f
Fix more
kdy1 Jun 3, 2024
4bdf889
Replace: Vc::<String>::default()
kdy1 Jun 3, 2024
1910823
Fix more
kdy1 Jun 3, 2024
9b17d87
Fix more
kdy1 Jun 3, 2024
1ba7502
Fix more
kdy1 Jun 3, 2024
ee19fc9
Fix more
kdy1 Jun 3, 2024
8a567dc
Fix more
kdy1 Jun 3, 2024
2326ad3
Fix more
kdy1 Jun 3, 2024
97bcbff
Fix more
kdy1 Jun 3, 2024
463092c
Fix more
kdy1 Jun 3, 2024
a38e963
Fix more
kdy1 Jun 3, 2024
2ac3d1b
Fix more
kdy1 Jun 3, 2024
129fa54
Fix more
kdy1 Jun 3, 2024
cfb01a1
Fix more
kdy1 Jun 3, 2024
0583854
Fix more
kdy1 Jun 3, 2024
879dd22
Fix more
kdy1 Jun 3, 2024
cced1be
Fix more
kdy1 Jun 3, 2024
33f9954
Fix more
kdy1 Jun 3, 2024
b1c81b7
Fix more
kdy1 Jun 3, 2024
90109be
Fix more
kdy1 Jun 3, 2024
a8c7cf7
Fix more
kdy1 Jun 3, 2024
a9e1fba
Fix more
kdy1 Jun 3, 2024
dba29d0
Fix more
kdy1 Jun 3, 2024
854bc22
Fix more
kdy1 Jun 3, 2024
abb5813
Fix more
kdy1 Jun 3, 2024
7128ccc
Fix more
kdy1 Jun 3, 2024
4a17ae3
Fix more
kdy1 Jun 3, 2024
03ab8a0
Fix more
kdy1 Jun 3, 2024
3173729
Fix more
kdy1 Jun 3, 2024
f2988a1
Fix more
kdy1 Jun 3, 2024
e10f547
Fix more
kdy1 Jun 3, 2024
9e52d6d
Fix more
kdy1 Jun 3, 2024
ea844a6
Fix more
kdy1 Jun 3, 2024
39a97c3
Fix more
kdy1 Jun 3, 2024
21e0250
Fix more
kdy1 Jun 3, 2024
f4a149a
Fix more
kdy1 Jun 3, 2024
49fbb1f
Fix more
kdy1 Jun 3, 2024
66bdd99
Fix more
kdy1 Jun 3, 2024
bd8d4df
Fix more
kdy1 Jun 3, 2024
bf2f639
Fix more
kdy1 Jun 3, 2024
cd05dc4
Fix more
kdy1 Jun 3, 2024
264d6a3
Fix more
kdy1 Jun 3, 2024
40b93aa
Fix more
kdy1 Jun 3, 2024
6b86959
Fix more
kdy1 Jun 3, 2024
9f78830
Fix more
kdy1 Jun 3, 2024
7de3fc0
Fix more
kdy1 Jun 3, 2024
e7a5114
Fix more
kdy1 Jun 3, 2024
50d5f08
Fix more
kdy1 Jun 3, 2024
fb88b30
Fix more
kdy1 Jun 3, 2024
80d104e
Fix more
kdy1 Jun 3, 2024
68f8343
Fix more
kdy1 Jun 3, 2024
83df610
Fix more
kdy1 Jun 3, 2024
a17c553
Fix more
kdy1 Jun 3, 2024
d68c011
Fix more
kdy1 Jun 3, 2024
1a4b12f
Fix more
kdy1 Jun 3, 2024
c3cffab
Fix more
kdy1 Jun 3, 2024
9b320d5
Fix more
kdy1 Jun 3, 2024
9c5ab3b
Fix more
kdy1 Jun 3, 2024
639726f
Fix more
kdy1 Jun 3, 2024
2f2b38c
Fix more
kdy1 Jun 3, 2024
16102dc
Fix more
kdy1 Jun 3, 2024
781f74b
Fix more
kdy1 Jun 3, 2024
3dca19f
Fix more
kdy1 Jun 3, 2024
24052b5
Fix more
kdy1 Jun 3, 2024
a935475
Fix more
kdy1 Jun 3, 2024
70942af
Fix more
kdy1 Jun 3, 2024
b1370eb
Fix more
kdy1 Jun 3, 2024
6d4726d
Fix more
kdy1 Jun 3, 2024
729e623
Fix more
kdy1 Jun 3, 2024
5526b1b
Fix more
kdy1 Jun 3, 2024
0b1fc38
Fix more
kdy1 Jun 3, 2024
0add0cb
Fix more
kdy1 Jun 3, 2024
da7d73c
Fix more
kdy1 Jun 3, 2024
c4fcfa4
Fix more
kdy1 Jun 3, 2024
37a5d26
Fix more
kdy1 Jun 3, 2024
abeef6f
Fix more
kdy1 Jun 3, 2024
cf34852
Fix more
kdy1 Jun 3, 2024
0d43ac3
Fix more
kdy1 Jun 3, 2024
3cf446f
Fix more
kdy1 Jun 3, 2024
9b058bf
Fix more
kdy1 Jun 3, 2024
db1a01d
Fix more
kdy1 Jun 3, 2024
09d84b1
Fix more
kdy1 Jun 3, 2024
3720fca
Fix more
kdy1 Jun 3, 2024
fe8ad3b
Fix more
kdy1 Jun 3, 2024
d420f20
Fix more
kdy1 Jun 3, 2024
792c185
Fix more
kdy1 Jun 3, 2024
3b60418
Fix more
kdy1 Jun 3, 2024
1a17e1c
Fix more
kdy1 Jun 3, 2024
d23dba1
Fix more
kdy1 Jun 4, 2024
887d34f
Fix more
kdy1 Jun 4, 2024
70ab567
Fix more
kdy1 Jun 4, 2024
b102bc8
Fix more
kdy1 Jun 4, 2024
de18584
Fix more
kdy1 Jun 4, 2024
5a09468
Fix more
kdy1 Jun 4, 2024
9536aac
impl ValueDebugFormat for RcStr
kdy1 Jun 4, 2024
ce06544
Update crates/turbo-tasks/src/primitives.rs
kdy1 Jun 5, 2024
1fef2c3
Update crates/turbo-tasks/src/task/task_input.rs
kdy1 Jun 5, 2024
696670e
impl
kdy1 Jun 5, 2024
0cab8a4
Move to own file
kdy1 Jun 5, 2024
895b72d
Default::default()
kdy1 Jun 5, 2024
1ddec4a
Remove mutate
kdy1 Jun 5, 2024
ed1411d
Fix
kdy1 Jun 5, 2024
cc15d25
Fix
kdy1 Jun 5, 2024
2306c26
Fix
kdy1 Jun 5, 2024
d29f2d3
Fix
kdy1 Jun 5, 2024
f11c06e
Fix
kdy1 Jun 5, 2024
dfe16c8
clippy
kdy1 Jun 5, 2024
5c25eee
fix tests
kdy1 Jun 5, 2024
486ea9f
Debug impl
kdy1 Jun 5, 2024
5679cb2
Update test refs
kdy1 Jun 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 24 additions & 20 deletions crates/node-file-trace/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ use serde::Deserialize;
use serde::Serialize;
use tokio::sync::mpsc::channel;
use turbo_tasks::{
backend::Backend, util::FormatDuration, TaskId, TransientInstance, TransientValue, TurboTasks,
UpdateInfo, Value, Vc,
backend::Backend, util::FormatDuration, RcStr, TaskId, TransientInstance, TransientValue,
TurboTasks, UpdateInfo, Value, Vc,
};
use turbo_tasks_fs::{
glob::Glob, DirectoryEntry, DiskFileSystem, FileSystem, FileSystemPath, ReadGlobResult,
Expand Down Expand Up @@ -188,7 +188,7 @@ impl Args {
}

async fn create_fs(name: &str, root: &str, watch: bool) -> Result<Vc<Box<dyn FileSystem>>> {
let fs = DiskFileSystem::new(name.to_string(), root.to_string(), vec![]);
let fs = DiskFileSystem::new(name.into(), root.into(), vec![]);
if watch {
fs.await?.start_watching()?;
} else {
Expand Down Expand Up @@ -232,17 +232,17 @@ async fn add_glob_results(
#[turbo_tasks::function]
async fn input_to_modules(
fs: Vc<Box<dyn FileSystem>>,
input: Vec<String>,
input: Vec<RcStr>,
exact: bool,
process_cwd: Option<String>,
context_directory: String,
process_cwd: Option<RcStr>,
context_directory: RcStr,
module_options: TransientInstance<ModuleOptionsContext>,
resolve_options: TransientInstance<ResolveOptionsContext>,
) -> Result<Vc<Modules>> {
let root = fs.root();
let process_cwd = process_cwd
.clone()
.map(|p| format!("/ROOT{}", p.trim_start_matches(&context_directory)));
.map(|p| format!("/ROOT{}", p.trim_start_matches(&*context_directory)).into());

let asset_context: Vc<Box<dyn AssetContext>> = Vc::upcast(create_module_asset(
root,
Expand Down Expand Up @@ -283,7 +283,7 @@ fn process_context(dir: &Path, context_directory: Option<&String>) -> Result<Str
.to_string())
}

fn make_relative_path(dir: &Path, context_directory: &str, input: &str) -> Result<String> {
fn make_relative_path(dir: &Path, context_directory: &str, input: &str) -> Result<RcStr> {
let mut input = PathBuf::from(input);
if !input.is_absolute() {
input = dir.join(input);
Expand All @@ -299,10 +299,11 @@ fn make_relative_path(dir: &Path, context_directory: &str, input: &str) -> Resul
Ok(input
.to_str()
.ok_or_else(|| anyhow!("input contains invalid characters"))?
.replace('\\', "/"))
.replace('\\', "/")
.into())
}

fn process_input(dir: &Path, context_directory: &str, input: &[String]) -> Result<Vec<String>> {
fn process_input(dir: &Path, context_directory: &str, input: &[String]) -> Result<Vec<RcStr>> {
input
.iter()
.map(|input| make_relative_path(dir, context_directory, input))
Expand All @@ -314,7 +315,7 @@ pub async fn start(
turbo_tasks: Option<&Arc<TurboTasks<MemoryBackend>>>,
module_options: Option<ModuleOptionsContext>,
resolve_options: Option<ResolveOptionsContext>,
) -> Result<Vec<String>> {
) -> Result<Vec<RcStr>> {
register();
let &CommonArgs {
memory_limit,
Expand Down Expand Up @@ -394,7 +395,7 @@ async fn run<B: Backend + 'static, F: Future<Output = ()>>(
final_finish: impl FnOnce(Arc<TurboTasks<B>>, TaskId, Duration) -> F,
module_options: Option<ModuleOptionsContext>,
resolve_options: Option<ResolveOptionsContext>,
) -> Result<Vec<String>> {
) -> Result<Vec<RcStr>> {
let &CommonArgs {
watch,
show_all,
Expand Down Expand Up @@ -494,7 +495,7 @@ async fn run<B: Backend + 'static, F: Future<Output = ()>>(
if has_return_value {
let output_read_ref = output.await?;
let output_iter = output_read_ref.iter().cloned();
sender.send(output_iter.collect::<Vec<String>>()).await?;
sender.send(output_iter.collect::<Vec<RcStr>>()).await?;
drop(sender);
}
Ok::<Vc<()>, _>(Default::default())
Expand All @@ -515,7 +516,7 @@ async fn main_operation(
args: TransientInstance<Args>,
module_options: TransientInstance<ModuleOptionsContext>,
resolve_options: TransientInstance<ResolveOptionsContext>,
) -> Result<Vc<Vec<String>>> {
) -> Result<Vc<Vec<RcStr>>> {
let dir = current_dir.into_value();
let args = &*args;
let &CommonArgs {
Expand All @@ -526,8 +527,11 @@ async fn main_operation(
ref process_cwd,
..
} = args.common();
let context_directory = process_context(&dir, context_directory.as_ref()).unwrap();
let context_directory: RcStr = process_context(&dir, context_directory.as_ref())
.unwrap()
.into();
let fs = create_fs("context directory", &context_directory, watch).await?;
let process_cwd = process_cwd.clone().map(RcStr::from);

match *args {
Args::Print { common: _ } => {
Expand All @@ -549,7 +553,7 @@ async fn main_operation(
.await?;
for asset in set.await?.iter() {
let path = asset.ident().path().await?;
result.insert(path.path.to_string());
result.insert(RcStr::from(&*path.path));
}
}

Expand Down Expand Up @@ -620,7 +624,7 @@ async fn main_operation(
#[turbo_tasks::function]
async fn create_module_asset(
root: Vc<FileSystemPath>,
process_cwd: Option<String>,
process_cwd: Option<RcStr>,
module_options: TransientInstance<ModuleOptionsContext>,
resolve_options: TransientInstance<ResolveOptionsContext>,
) -> Result<Vc<ModuleAssetContext>> {
Expand All @@ -635,12 +639,12 @@ async fn create_module_asset(
let glob_mappings = vec![
(
root,
Glob::new("**/*/next/dist/server/next.js".to_string()),
Glob::new("**/*/next/dist/server/next.js".into()),
ImportMapping::Ignore.into(),
),
(
root,
Glob::new("**/*/next/dist/bin/next".to_string()),
Glob::new("**/*/next/dist/bin/next".into()),
ImportMapping::Ignore.into(),
),
];
Expand All @@ -662,7 +666,7 @@ async fn create_module_asset(
compile_time_info,
ModuleOptionsContext::clone(&*module_options).cell(),
resolve_options.cell(),
Vc::cell("node_file_trace".to_string()),
Vc::cell("node_file_trace".into()),
))
}

Expand Down
4 changes: 3 additions & 1 deletion crates/node-file-trace/src/nft_json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ impl OutputAsset for NftJsonAsset {
async fn ident(&self) -> Result<Vc<AssetIdent>> {
let path = self.entry.ident().path().await?;
Ok(AssetIdent::from_path(
path.fs.root().join(format!("{}.nft.json", path.path)),
path.fs
.root()
.join(format!("{}.nft.json", path.path).into()),
))
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/turbo-tasks-env/src/command_line.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use indexmap::IndexMap;
use turbo_tasks::Vc;
use turbo_tasks::{RcStr, Vc};

use crate::{sorted_env_vars, EnvMap, ProcessEnv, GLOBAL_ENV_LOCK};

Expand All @@ -16,7 +16,7 @@ impl CommandLineProcessEnv {
}

/// Clones the current env vars into a IndexMap.
fn env_snapshot() -> IndexMap<String, String> {
fn env_snapshot() -> IndexMap<RcStr, RcStr> {
let _lock = GLOBAL_ENV_LOCK.lock().unwrap();
sorted_env_vars()
}
Expand Down
4 changes: 2 additions & 2 deletions crates/turbo-tasks-env/src/custom.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use anyhow::Result;
use turbo_tasks::Vc;
use turbo_tasks::{RcStr, Vc};

use crate::{case_insensitive_read, EnvMap, ProcessEnv};

Expand Down Expand Up @@ -32,7 +32,7 @@ impl ProcessEnv for CustomProcessEnv {
}

#[turbo_tasks::function]
async fn read(&self, name: String) -> Result<Vc<Option<String>>> {
async fn read(&self, name: RcStr) -> Result<Vc<Option<RcStr>>> {
let custom = case_insensitive_read(self.custom, name.clone());
match &*custom.await? {
Some(_) => Ok(custom),
Expand Down
8 changes: 2 additions & 6 deletions crates/turbo-tasks-env/src/dotenv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::{env, sync::MutexGuard};

use anyhow::{anyhow, Context, Result};
use indexmap::IndexMap;
use turbo_tasks::{ValueToString, Vc};
use turbo_tasks::{RcStr, ValueToString, Vc};
use turbo_tasks_fs::{FileContent, FileSystemPath};

use crate::{sorted_env_vars, EnvMap, ProcessEnv, GLOBAL_ENV_LOCK};
Expand Down Expand Up @@ -84,11 +84,7 @@ impl ProcessEnv for DotenvProcessEnv {
}

/// Restores the global env variables to mirror `to`.
fn restore_env(
from: &IndexMap<String, String>,
to: &IndexMap<String, String>,
_lock: &MutexGuard<()>,
) {
fn restore_env(from: &IndexMap<RcStr, RcStr>, to: &IndexMap<RcStr, RcStr>, _lock: &MutexGuard<()>) {
for key in from.keys() {
if !to.contains_key(key) {
env::remove_var(key);
Expand Down
17 changes: 10 additions & 7 deletions crates/turbo-tasks-env/src/filter.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use anyhow::Result;
use indexmap::IndexMap;
use turbo_tasks::Vc;
use turbo_tasks::{RcStr, Vc};

use crate::{EnvMap, ProcessEnv};

Expand All @@ -9,16 +9,19 @@ use crate::{EnvMap, ProcessEnv};
#[turbo_tasks::value]
pub struct FilterProcessEnv {
prior: Vc<Box<dyn ProcessEnv>>,
filters: Vec<String>,
filters: Vec<RcStr>,
}

#[turbo_tasks::value_impl]
impl FilterProcessEnv {
#[turbo_tasks::function]
pub fn new(prior: Vc<Box<dyn ProcessEnv>>, filters: Vec<String>) -> Vc<Self> {
pub fn new(prior: Vc<Box<dyn ProcessEnv>>, filters: Vec<RcStr>) -> Vc<Self> {
FilterProcessEnv {
prior,
filters: filters.into_iter().map(|f| f.to_uppercase()).collect(),
filters: filters
.into_iter()
.map(|f| f.to_uppercase().into())
.collect(),
}
.cell()
}
Expand All @@ -33,7 +36,7 @@ impl ProcessEnv for FilterProcessEnv {
for (key, value) in &*prior {
let uppercase = key.to_uppercase();
for filter in &self.filters {
if uppercase.starts_with(filter) {
if uppercase.starts_with(&**filter) {
filtered.insert(key.clone(), value.clone());
break;
}
Expand All @@ -43,9 +46,9 @@ impl ProcessEnv for FilterProcessEnv {
}

#[turbo_tasks::function]
fn read(&self, name: String) -> Vc<Option<String>> {
fn read(&self, name: RcStr) -> Vc<Option<RcStr>> {
for filter in &self.filters {
if name.to_uppercase().starts_with(filter) {
if name.to_uppercase().starts_with(&**filter) {
return self.prior.read(name);
}
}
Expand Down
20 changes: 11 additions & 9 deletions crates/turbo-tasks-env/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ use std::{env, sync::Mutex};

use anyhow::Result;
use indexmap::IndexMap;
use turbo_tasks::Vc;
use turbo_tasks::{RcStr, Vc};

pub use self::{
command_line::CommandLineProcessEnv, custom::CustomProcessEnv, dotenv::DotenvProcessEnv,
filter::FilterProcessEnv,
};

#[turbo_tasks::value(transparent)]
pub struct EnvMap(#[turbo_tasks(trace_ignore)] IndexMap<String, String>);
pub struct EnvMap(#[turbo_tasks(trace_ignore)] IndexMap<RcStr, RcStr>);

#[turbo_tasks::value_impl]
impl EnvMap {
Expand All @@ -35,7 +35,7 @@ impl ProcessEnv for EnvMap {
}

#[turbo_tasks::function]
async fn read(self: Vc<Self>, name: String) -> Vc<Option<String>> {
async fn read(self: Vc<Self>, name: RcStr) -> Vc<Option<RcStr>> {
case_insensitive_read(self, name)
}
}
Expand All @@ -51,23 +51,25 @@ pub trait ProcessEnv {
fn read_all(self: Vc<Self>) -> Vc<EnvMap>;

/// Reads a single env variable. Ignores casing.
fn read(self: Vc<Self>, name: String) -> Vc<Option<String>> {
fn read(self: Vc<Self>, name: RcStr) -> Vc<Option<RcStr>> {
case_insensitive_read(self.read_all(), name)
}
}

pub fn sorted_env_vars() -> IndexMap<String, String> {
let mut vars = env::vars().collect::<IndexMap<_, _>>();
pub fn sorted_env_vars() -> IndexMap<RcStr, RcStr> {
let mut vars = env::vars()
.map(|(k, v)| (k.into(), v.into()))
.collect::<IndexMap<_, _>>();
vars.sort_keys();
vars
}

#[turbo_tasks::function]
pub async fn case_insensitive_read(map: Vc<EnvMap>, name: String) -> Result<Vc<Option<String>>> {
pub async fn case_insensitive_read(map: Vc<EnvMap>, name: RcStr) -> Result<Vc<Option<RcStr>>> {
Ok(Vc::cell(
to_uppercase_map(map)
.await?
.get(&name.to_uppercase())
.get(&RcStr::from(name.to_uppercase()))
.cloned(),
))
}
Expand All @@ -77,7 +79,7 @@ async fn to_uppercase_map(map: Vc<EnvMap>) -> Result<Vc<EnvMap>> {
let map = &*map.await?;
let mut new = IndexMap::with_capacity(map.len());
for (k, v) in map {
new.insert(k.to_uppercase(), v.clone());
new.insert(k.to_uppercase().into(), v.clone());
}
Ok(Vc::cell(new))
}
Expand Down
Loading
Loading