Skip to content

Commit 238e3f5

Browse files
committed
perf
1 parent 9be6f5e commit 238e3f5

File tree

5 files changed

+701
-691
lines changed

5 files changed

+701
-691
lines changed

benches/bench_source_map.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,6 @@ pub fn benchmark_parse_source_map_from_json(b: &mut Bencher) {
1919
})
2020
}
2121

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-
2922
pub fn benchmark_stringify_source_map_to_json(b: &mut Bencher) {
3023
let source = SourceMap::from_json(ANTD_MIN_JS_MAP).unwrap();
3124
b.iter(|| {

src/cached_source.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -119,19 +119,17 @@ impl Source for CachedSource {
119119
fn map(&self, options: &MapOptions) -> Option<SourceMap> {
120120
if options.columns {
121121
self.0.with_dependent(|owner, dependent| {
122-
dependent.cached_colomns_map.get_or_init(|| {
123-
let map = owner.inner.map(options);
124-
unsafe { std::mem::transmute::<Option<SourceMap>, Option<SourceMap<'static>>>(map) }
125-
})
122+
dependent
123+
.cached_colomns_map
124+
.get_or_init(|| owner.inner.map(options).map(|m| m.into_owned()))
126125
.as_ref()
127126
.map(|m| m.as_borrowed())
128127
})
129128
} else {
130129
self.0.with_dependent(|owner, dependent| {
131-
dependent.cached_line_only_map.get_or_init(|| {
132-
let map = owner.inner.map(options);
133-
unsafe { std::mem::transmute::<Option<SourceMap>, Option<SourceMap<'static>>>(map) }
134-
})
130+
dependent
131+
.cached_line_only_map
132+
.get_or_init(|| owner.inner.map(options).map(|m| m.into_owned()))
135133
.as_ref()
136134
.map(|m| m.as_borrowed())
137135
})

src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ mod raw_source;
1212
mod replace_source;
1313
mod rope;
1414
mod source;
15+
mod source_map;
1516
mod source_map_source;
1617
mod with_indices;
1718

@@ -24,8 +25,8 @@ pub use replace_source::{ReplaceSource, ReplacementEnforce};
2425
pub use rope::Rope;
2526
pub use source::{
2627
BoxSource, MapOptions, Mapping, OriginalLocation, Source, SourceExt,
27-
SourceMap,
2828
};
29+
pub use source_map::SourceMap;
2930
pub use source_map_source::{
3031
SourceMapSource, SourceMapSourceOptions, WithoutOriginalOptions,
3132
};

0 commit comments

Comments
 (0)