Skip to content

Commit 43bf168

Browse files
committed
chore: merge origin main
2 parents 4ec350d + d86a37a commit 43bf168

File tree

6 files changed

+75
-13
lines changed

6 files changed

+75
-13
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "rspack_sources"
3-
version = "0.4.10"
3+
version = "0.4.11"
44
edition = "2021"
55
authors = ["h-a-n-a <[email protected]>", "ahabhgk <[email protected]>"]
66
resolver = "2"

benches/bench.rs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#![allow(missing_docs)]
22

33
mod bench_complex_replace_source;
4+
mod bench_source_map;
45

56
use std::collections::HashMap;
67

@@ -16,6 +17,10 @@ use rspack_sources::{
1617
};
1718

1819
use bench_complex_replace_source::benchmark_complex_replace_source;
20+
use bench_source_map::{
21+
benchmark_parse_source_map_from_json, benchmark_source_map_clone,
22+
benchmark_stringify_source_map_to_json,
23+
};
1924

2025
const HELLOWORLD_JS: &str = include_str!(concat!(
2126
env!("CARGO_MANIFEST_DIR"),
@@ -41,14 +46,6 @@ const BUNDLE_JS_MAP: &str = include_str!(concat!(
4146
env!("CARGO_MANIFEST_DIR"),
4247
"/benches/fixtures/transpile-rollup/files/bundle.js.map"
4348
));
44-
const ANTD_MIN_JS: &str = include_str!(concat!(
45-
env!("CARGO_MANIFEST_DIR"),
46-
"/benches/fixtures/antd-mini/antd.min.js"
47-
));
48-
const ANTD_MIN_JS_MAP: &str = include_str!(concat!(
49-
env!("CARGO_MANIFEST_DIR"),
50-
"/benches/fixtures/antd-mini/antd.min.js.map"
51-
));
5249

5350
fn benchmark_concat_generate_string(b: &mut Bencher) {
5451
let sms_minify = SourceMapSource::new(SourceMapSourceOptions {
@@ -251,6 +248,18 @@ fn bench_rspack_sources(criterion: &mut Criterion) {
251248
group
252249
.bench_function("complex_replace_source", benchmark_complex_replace_source);
253250

251+
group.bench_function(
252+
"parse_source_map_from_json",
253+
benchmark_parse_source_map_from_json,
254+
);
255+
256+
group.bench_function("source_map_clone", benchmark_source_map_clone);
257+
258+
group.bench_function(
259+
"stringify_source_map_to_json",
260+
benchmark_stringify_source_map_to_json,
261+
);
262+
254263
group.finish();
255264
}
256265

benches/bench_source_map.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#![allow(missing_docs)]
2+
3+
#[cfg(not(codspeed))]
4+
pub use criterion::*;
5+
6+
#[cfg(codspeed)]
7+
pub use codspeed_criterion_compat::*;
8+
9+
use rspack_sources::SourceMap;
10+
11+
const ANTD_MIN_JS_MAP: &str = include_str!(concat!(
12+
env!("CARGO_MANIFEST_DIR"),
13+
"/benches/fixtures/antd-mini/antd.min.js.map"
14+
));
15+
16+
pub fn benchmark_parse_source_map_from_json(b: &mut Bencher) {
17+
b.iter(|| {
18+
black_box(SourceMap::from_json(black_box(ANTD_MIN_JS_MAP)).unwrap())
19+
})
20+
}
21+
22+
pub fn benchmark_source_map_clone(b: &mut Bencher) {
23+
let source = SourceMap::from_json(ANTD_MIN_JS_MAP).unwrap();
24+
b.iter(|| {
25+
let _ = black_box(source.clone());
26+
})
27+
}
28+
29+
pub fn benchmark_stringify_source_map_to_json(b: &mut Bencher) {
30+
let source = SourceMap::from_json(ANTD_MIN_JS_MAP).unwrap();
31+
b.iter(|| {
32+
let _ = black_box(source.to_json().unwrap());
33+
})
34+
}

src/source.rs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,8 @@ pub struct SourceMap {
225225
source_root: Option<Arc<str>>,
226226
#[serde(rename = "debugId", skip_serializing_if = "Option::is_none")]
227227
debug_id: Option<Arc<str>>,
228+
#[serde(rename = "ignoreList", skip_serializing_if = "Option::is_none")]
229+
ignore_list: Option<Vec<u32>>,
228230
}
229231

230232
impl std::fmt::Debug for SourceMap {
@@ -252,6 +254,7 @@ impl Hash for SourceMap {
252254
self.sources_content.hash(state);
253255
self.names.hash(state);
254256
self.source_root.hash(state);
257+
self.ignore_list.hash(state);
255258
}
256259
}
257260

@@ -278,6 +281,7 @@ impl SourceMap {
278281
names: names.into(),
279282
source_root: None,
280283
debug_id: None,
284+
ignore_list: None,
281285
}
282286
}
283287

@@ -291,6 +295,16 @@ impl SourceMap {
291295
self.file = file.map(Into::into);
292296
}
293297

298+
/// Get the ignoreList field in [SourceMap].
299+
pub fn ignore_list(&self) -> Option<&[u32]> {
300+
self.ignore_list.as_deref()
301+
}
302+
303+
/// Set the ignoreList field in [SourceMap].
304+
pub fn set_ignore_list<T: Into<Vec<u32>>>(&mut self, ignore_list: Option<T>) {
305+
self.ignore_list = ignore_list.map(Into::into);
306+
}
307+
294308
/// Get the decoded mappings in [SourceMap].
295309
pub fn decoded_mappings(&self) -> impl Iterator<Item = Mapping> + '_ {
296310
decode_mappings(self)
@@ -415,6 +429,11 @@ impl SourceMap {
415429
.get_str("sourceRoot")
416430
.map(|v| Arc::from(v.to_string())),
417431
debug_id: value.get_str("debugId").map(|v| Arc::from(v.to_string())),
432+
ignore_list: value.get_array("ignoreList").map(|v| {
433+
v.into_iter()
434+
.map(|n| n.as_u32().unwrap_or_default())
435+
.collect::<Vec<_>>()
436+
}),
418437
})
419438
}
420439

@@ -426,7 +445,7 @@ impl SourceMap {
426445
}
427446

428447
/// Generate source map to a json string.
429-
pub fn to_json(self) -> Result<String> {
448+
pub fn to_json(&self) -> Result<String> {
430449
let json = simd_json::to_string(&self)?;
431450
Ok(json)
432451
}
@@ -539,7 +558,7 @@ mod tests {
539558
RawBufferSource::from("a".as_bytes()).hash(&mut state);
540559
(&RawSource::from("h") as &dyn Source).hash(&mut state);
541560
ReplaceSource::new(RawSource::from("i").boxed()).hash(&mut state);
542-
assert_eq!(format!("{:x}", state.finish()), "1b50b537fa997c34");
561+
assert_eq!(format!("{:x}", state.finish()), "6abed98aa11f84e5");
543562
}
544563

545564
#[test]

src/source_map_source.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ mod tests {
297297

298298
let mut hasher = twox_hash::XxHash64::default();
299299
sms1.hash(&mut hasher);
300-
assert_eq!(format!("{:x}", hasher.finish()), "d136621583d4618c");
300+
assert_eq!(format!("{:x}", hasher.finish()), "736934c6e249aa6e");
301301
}
302302

303303
#[test]

0 commit comments

Comments
 (0)