mirror of
https://github.com/danbulant/oxc
synced 2026-05-25 04:42:10 +00:00
feat(sourcemap): add "rayon" feature (#3198)
This commit is contained in:
parent
9b93a17429
commit
7363e14335
5 changed files with 41 additions and 12 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
|
@ -1620,6 +1620,7 @@ name = "oxc_sourcemap"
|
||||||
version = "0.12.5"
|
version = "0.12.5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"base64-simd",
|
"base64-simd",
|
||||||
|
"cfg-if",
|
||||||
"rayon",
|
"rayon",
|
||||||
"rustc-hash",
|
"rustc-hash",
|
||||||
"serde",
|
"serde",
|
||||||
|
|
|
||||||
|
|
@ -171,6 +171,8 @@ similar = "2.5.0"
|
||||||
textwrap = "0.16.0"
|
textwrap = "0.16.0"
|
||||||
unicode-width = "0.1.12"
|
unicode-width = "0.1.12"
|
||||||
saphyr = "0.0.1"
|
saphyr = "0.0.1"
|
||||||
|
base64-simd = "0.8"
|
||||||
|
cfg-if = "1.0.0"
|
||||||
|
|
||||||
[workspace.metadata.cargo-shear]
|
[workspace.metadata.cargo-shear]
|
||||||
ignored = ["napi", "oxc_traverse"]
|
ignored = ["napi", "oxc_traverse"]
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,13 @@ doctest = false
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
rustc-hash = { workspace = true }
|
rustc-hash = { workspace = true }
|
||||||
rayon = { workspace = true }
|
|
||||||
serde = { workspace = true, features = ["derive"] }
|
serde = { workspace = true, features = ["derive"] }
|
||||||
serde_json = { workspace = true }
|
serde_json = { workspace = true }
|
||||||
base64-simd = "0.8"
|
base64-simd = { workspace = true }
|
||||||
|
cfg-if = { workspace = true }
|
||||||
|
|
||||||
|
rayon = { workspace = true, optional = true }
|
||||||
|
|
||||||
|
[features]
|
||||||
|
default = []
|
||||||
|
rayon = ["dep:rayon"]
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ use crate::error::{Error, Result};
|
||||||
/// - Quote `source_content` at parallel.
|
/// - Quote `source_content` at parallel.
|
||||||
/// - If you using `ConcatSourceMapBuilder`, serialize `tokens` to vlq `mappings` at parallel.
|
/// - If you using `ConcatSourceMapBuilder`, serialize `tokens` to vlq `mappings` at parallel.
|
||||||
use crate::{token::TokenChunk, SourceMap, Token};
|
use crate::{token::TokenChunk, SourceMap, Token};
|
||||||
|
#[cfg(feature = "rayon")]
|
||||||
use rayon::prelude::*;
|
use rayon::prelude::*;
|
||||||
|
|
||||||
// Here using `serde_json::to_string` to serialization `names/source_contents/sources`.
|
// Here using `serde_json::to_string` to serialization `names/source_contents/sources`.
|
||||||
|
|
@ -40,11 +41,21 @@ pub fn encode(sourcemap: &SourceMap) -> Result<String> {
|
||||||
// Quote `source_content` at parallel.
|
// Quote `source_content` at parallel.
|
||||||
if let Some(source_contents) = &sourcemap.source_contents {
|
if let Some(source_contents) = &sourcemap.source_contents {
|
||||||
buf.push_str("],\"sourcesContent\":[");
|
buf.push_str("],\"sourcesContent\":[");
|
||||||
let quote_source_contents = source_contents
|
cfg_if::cfg_if! {
|
||||||
.par_iter()
|
if #[cfg(feature = "rayon")] {
|
||||||
.map(|x| serde_json::to_string(x.as_ref()))
|
let quote_source_contents = source_contents
|
||||||
.collect::<std::result::Result<Vec<_>, serde_json::Error>>()
|
.par_iter()
|
||||||
.map_err(Error::from)?;
|
.map(|x| serde_json::to_string(x.as_ref()))
|
||||||
|
.collect::<std::result::Result<Vec<_>, serde_json::Error>>()
|
||||||
|
.map_err(Error::from)?;
|
||||||
|
} else {
|
||||||
|
let quote_source_contents = source_contents
|
||||||
|
.iter()
|
||||||
|
.map(|x| serde_json::to_string(x.as_ref()))
|
||||||
|
.collect::<std::result::Result<Vec<_>, serde_json::Error>>()
|
||||||
|
.map_err(Error::from)?;
|
||||||
|
}
|
||||||
|
};
|
||||||
buf.push_str("e_source_contents.join(","));
|
buf.push_str("e_source_contents.join(","));
|
||||||
}
|
}
|
||||||
if let Some(x_google_ignore_list) = &sourcemap.x_google_ignore_list {
|
if let Some(x_google_ignore_list) = &sourcemap.x_google_ignore_list {
|
||||||
|
|
@ -70,10 +81,19 @@ fn serialize_sourcemap_mappings(sm: &SourceMap) -> String {
|
||||||
},
|
},
|
||||||
|token_chunks| {
|
|token_chunks| {
|
||||||
// Serialize `tokens` to vlq `mappings` at parallel.
|
// Serialize `tokens` to vlq `mappings` at parallel.
|
||||||
token_chunks
|
cfg_if::cfg_if! {
|
||||||
.par_iter()
|
if #[cfg(feature = "rayon")] {
|
||||||
.map(|token_chunk| serialize_mappings(&sm.tokens, token_chunk))
|
token_chunks
|
||||||
.collect::<String>()
|
.par_iter()
|
||||||
|
.map(|token_chunk| serialize_mappings(&sm.tokens, token_chunk))
|
||||||
|
.collect::<String>()
|
||||||
|
} else {
|
||||||
|
token_chunks
|
||||||
|
.iter()
|
||||||
|
.map(|token_chunk| serialize_mappings(&sm.tokens, token_chunk))
|
||||||
|
.collect::<String>()
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -75,7 +75,7 @@ oxc_span = { workspace = true, optional = true }
|
||||||
oxc_tasks_common = { workspace = true, optional = true }
|
oxc_tasks_common = { workspace = true, optional = true }
|
||||||
oxc_transformer = { workspace = true, optional = true }
|
oxc_transformer = { workspace = true, optional = true }
|
||||||
oxc_codegen = { workspace = true, optional = true }
|
oxc_codegen = { workspace = true, optional = true }
|
||||||
oxc_sourcemap = { workspace = true, optional = true }
|
oxc_sourcemap = { workspace = true, features = ["rayon"], optional = true }
|
||||||
|
|
||||||
criterion = { package = "criterion2", version = "0.8.0", default-features = false }
|
criterion = { package = "criterion2", version = "0.8.0", default-features = false }
|
||||||
serde = { workspace = true, optional = true }
|
serde = { workspace = true, optional = true }
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue